intdiv
Performs integer division.
Available since: PHP 7.0
Syntax
intdiv(int $num1, int $num2): intParameters
| Parameter | Type | Description |
|---|---|---|
| $num1 | int | The dividend. |
| $num2 | int | The divisor. |
Return value
intThe integer part of `$num1` divided by `$num2`.
Examples
The integer part and the remainder:
<?php
echo intdiv(10, 3), "\n";
echo 10 % 3;Output:
3
1Regular division returns a float:
<?php
var_dump(intdiv(7, 2));
var_dump(7 / 2);Output:
int(3)
float(3.5)Notes
Dividing by zero throws a DivisionByZeroError. The fraction is dropped rather than rounded: intdiv(-7, 2) gives -3.
See also
Related recipes
In the tutorial
- Operators — Arithmetic, comparison and logical operators in PHP, and operator precedence.