Thursday, October 9, 2025
HomeLanguagesPHP | bcmod() Function

PHP | bcmod() Function

The bcmod() function in PHP is an inbuilt function and is used to calculate modulus of an arbitrary precision numbers. This function accepts an arbitrary precision number and returns the modulus of that number after scaling the result to a specified precision.

Syntax:

string bcadd ( $dividend, $modulus)

Parameters: This function accepts two parameters as shown in the above syntax and explained below:

  • $dividend: This parameter is of string type and represents the dividend which will be divided by the given modulus value $modulus. This parameter is mandatory.
  • $modulus: This parameter is of string type and represents the modulus. This parameter is mandatory.

Return Value: This function returns the remainder when $dividend is divided by $modulus. In other words, it returns the value equivalent to ($dividend % $modulus). If $modulus is zero, then this function returns NULL.

Examples:

Input:  $dividend = 11, $modulus = 3
Output: 2

Input:  $dividend = 3, $modulus = 11
Output: 3

Below programs illustrate the bcmod() function in PHP :

Program 1:




<?php
// PHP program to illustrate bcmod() function
   
// input numbers with arbitrary precision
$dividend = "11";
$modulus = "3";
   
// calculates the modulus
$res = bcmod($dividend, $modulus);
  
echo $res;
   
?>


Output:

2

Program 2:




<?php
// PHP program to illustrate bcmod() function
   
// input numbers with arbitrary precision
$dividend = "3";
$modulus = "11";
   
// calculates the modulus
$res = bcmod($dividend, $modulus);
  
echo $res;
   
?>


Output:

3

Reference:
http://php.net/manual/en/function.bcmod.php

Last Updated :
20 Apr, 2018
Like Article
Save Article

<!–

–>

Similar Reads
Related Tutorials
RELATED ARTICLES

Most Popular

Dominic
32348 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6715 POSTS0 COMMENTS
Nicole Veronica
11878 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6837 POSTS0 COMMENTS
Ted Musemwa
7095 POSTS0 COMMENTS
Thapelo Manthata
6791 POSTS0 COMMENTS
Umr Jansen
6791 POSTS0 COMMENTS