How to calculate the mod of two integers without using modulus operator in PHP

1 Answer

0 votes
function mod($a, $b) {
   $div = (int)($a / $b);
   
   return $a - $b * $div;
}

echo mod(5, 3) . "<br />";
echo mod(13, 5) . "<br />";


/*
run:

2
3
 
*/

 



answered Feb 26, 2019 by avibootz
...