Open In App

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:

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


Article Tags :