Skip to content
Advertisement

Dividing with a remainder in PHP

I have a part in my code where I need to divide and have a remainder instead of a decimal answer.

How can I do this?

Advertisement

Answer

You can do what you are describing using the “%” (modulus) operator. The following code is an example of dividing with a remainder.

$remainder=$num % $divideby;
$number=explode('.',($num / $divideby));
$answer=$number[0];
echo $answer.' remainder '.$remainder;
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement