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;