Example 1 — Find a remainder
Use fmod() with whole numbers and with decimals.
<?php
echo fmod(10, 3) . PHP_EOL;
echo fmod(10.5, 3) . PHP_EOL;
echo fmod(9, 3) . PHP_EOL; How It Works
- 10 divided by 3 is 3 with 1 left over, so fmod(10, 3) is 1.
- 10.5 divided by 3 is 3 with 1.5 left over.
- 9 divided by 3 has nothing left, so the remainder is 0.
- The values are floats but PHP prints them in a short form.

