find the remainder of two numbers in php

To find the remainder of two numbers in PHP, you can use the modulus operator (%). The modulus operator gives the remainder of the division of the first operand by the second.

Here's how to use the modulus operator in PHP:

main.php
$number1 = 10;
$number2 = 3;

$remainder = $number1 % $number2;

echo "The remainder of $number1 divided by $number2 is $remainder.";
134 chars
7 lines

Output:

main.php
The remainder of 10 divided by 3 is 1.
39 chars
2 lines

In this example, the modulus operator finds the remainder of $number1 divided by $number2 and assigns it to $remainder. Then, the echo statement displays the result.

Note that the modulus operator (%) can only be used with integer operands.

gistlibby LogSnag