intdiv() performs integer division and returns the integer quotient. The divisor must not be zero.
$quotient = intdiv(17, 5);
echo $quotient; // 3
This is the recommended starting pattern. The detailed examples below are retained and modernized for additional variations and explanation.
<?Php
echo intdiv(4,9); // Output 0
echo "<br>";
echo intdiv(3,5); // Output 0
echo "<br>";
echo intdiv(20,10); // Output is 2
echo "<br>";
echo intdiv(2,13); // Output is 0
echo "<br>";
echo intdiv(4,100); // Output is 0
echo "<br>";
echo intdiv(100,4); // Output is 25
?>
Syntax
int intdiv ( int $dividend , int $divisor )
| Parameter | DESCRIPTION |
|---|---|
| $dividend | Required : dividend of the division. |
| $divisior | Required : Divisor of the division. |
try {
echo intdiv(10, 0); // Will throw DivisionByZeroError
} catch (DivisionByZeroError $e) {
echo "Cannot divide by zero!";
}
echo intdiv(-10, 3); // Output: -3
echo intdiv(1000000, 500); // Output: 2000
echo intdiv(15, -4); // Output: -3
echo intdiv(20, 5); // Output: 4
These examples show how `intdiv()` handles large numbers, mixed positive/negative values, and evenly divisible integers.
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.