PHP intdiv() – Integer Division Function
The article explains PHP's intdiv() function, describing its syntax, parameters, return value, and providing multiple code examples that illustrate integer division results, edge‑case behavior with large integers, division by zero, and the resulting errors.
The intdiv() function returns the integer part of the division of a dividend by a divisor.
Syntax: int intdiv(int $dividend, int $divisor) Parameters: $dividend – the dividend. $divisor – the divisor.
Return value: The integer quotient of $dividend divided by $divisor.
Examples:
<?php
var_dump(intdiv(3, 2)); // int(1)
var_dump(intdiv(-3, 2)); // int(-2)
var_dump(intdiv(3, -2)); // int(-2)
var_dump(intdiv(-3, -2)); // int(1)
var_dump(intdiv(PHP_INT_MAX, PHP_INT_MAX)); // int(1)
var_dump(intdiv(PHP_INT_MIN, PHP_INT_MIN)); // int(1)
var_dump(intdiv(PHP_INT_MIN, -1)); // Fatal error: Uncaught ArithmeticError
var_dump(intdiv(1, 0)); // Fatal error: Uncaught DivisionByZeroError
?>Output:
int(1)
int(-2)
int(-2)
int(1)
int(1)
int(1)
Fatal error: Uncaught ArithmeticError: Division of PHP_INT_MIN by -1 is not an integer in %s on line 8
Fatal error: Uncaught DivisionByZeroError: Division by zero in %s on line 9The function throws an ArithmeticError when the division would overflow and a DivisionByZeroError when the divisor is zero.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
