int intdiv ($dividend, $divisor)Parameters: the function takes two parameters as follows:
- $divnd: this signed integer parameter refers to the number to be separated.
- $divisor: this signed integer parameter refers to to the number to be used as the divisor.
Input: $dividend = 5, $divisor = 2 Output: 2 Input: $dividend = -11, $divisor = 2 Output: -5Exception / Error::The function raises an exception in the following cases:
- If we pass the divisor 0, the function will throw a DivisionByZeroError.
- If we pass PHP_INT_MIN as the dividend and -1 as divisor, an ArithmeticError is thrown. The following program illustrates how intdiv works in PHP:
php
// PHP -code to illustrate the work
// intdiv() functions
$dividend
= 19;
$divisor
= 3;
echo
intdiv (
$dividend
,
$divisor
);
?>
Output:6Looking so far, many might think this function is equivalent to
floor ($dividend / $divisor)but an example will clarify the difference.
php
// PHP code to differentiate
// intdiv() and floor()
$dividend
= -19;
$divisor
= 3;
echo
intdiv (
$dividend
,
$divisor
).
""
.
floor
(
$dividend
/
$divisor
) ;
?>
Output:-6 - 7Important points to pay attention to :
- The intdiv() function returns the quotient of an integer division.
- The function can throw exceptions, so the developer should tackle the edge cases.
- The function is not equivalent to the floor function applied to float division or "/".
http://php.net/manual/en/function.intdiv. php