Monday 2 February 2015

Modulus of two variables in PHP

Modulus of two variables in PHP

We can get the modulus of two number by using math function modulus (%). This is same as reminder of a math division process of two number. Let us see this by the example script. 

We can see the modulus of 160 and 15 is equal to 10. Same way the reminder or modulus is 0 if two numbers are 150 and 10.
$num1 = 160;
$num2 = 15;
echo "<P>The  value of variable $num1 is $num1 &  $num2 is $num2</P>";

$result = $num1 % $num2;
echo "<P>The modulus of these numbers  is $result</P>";

0 comments:

Post a Comment