Use fmod() when the dividend or divisor is a floating-point value. For integer modulus, use the % operator instead.
$remainder = fmod(5.7, 1.3);
echo $remainder; // approximately 0.5
This is the recommended starting pattern. The detailed examples below are retained and modernized for additional variations and explanation.
<?Php
echo fmod(5,2); // Output 1
echo "<br>";
echo fmod(10,2); // Output 0
echo "<br>";
echo fmod(13,2); // Output is 1
echo "<br>";
echo fmod(6,3); // Output is 0
?>
Syntax
float fmod(float $X,float $y);
$X is the dividend
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.