fmod()
fmod() — Returns the floating point remainder (modulo) of the division of the arguments.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Returns the floating point remainder of dividing the dividend (num1) by the divisor (num2). The remainder (r) is defined as: num1 = i * num2 + r, for some integer i. If num2 is non-zero, r has the same sign as num1 and a magnitude less than the magnitude of num2.
Signature
fmod(float $num1, float $num2): float
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $num1 | float | The dividend |
| $num2 | float | The divisor |
Return value
The floating point remainder of num1/num2. NAN (float) if the second argument is 0.
Example
A runnable snippet:
$x = 5.7; $y = 1.3; $r = fmod($x, $y); // $r equals 0.5, because 4 * 1.3 + 0.5 = 5.7 var_dump($x, $y, $r);
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page fmod() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.