PHP | intdiv() Function - GeeksforGeeks

09 Mar, 2018
intdiv stands for integer division. This function returns the integer quotient of the division of the given dividend and divisor. This function internally removes the remainder from the dividend to make it evenly divisible by the divisor and returns the quotient after division.
Syntax:
int intdiv($dividend, $divisor)

Parameters: The function takes two parameters as follows:
$dividend: This signed integer parameter refers to the number to be divided.
$divisor: This signed integer parameter refers to the number to be used as the divisor.
Return Type: This function returns the quotient calculated.
Examples:
Input :  $dividend = 5, $divisor = 2
Output : 2

Input : $dividend = -11, $divisor = 2
Output : -5        

Exception/Error:: The function raises exception in following cases:
If we pass the divisor as 0, then the function raises DivisionByZeroError exception.
If we pass PHP_INT_MIN as the dividend and -1 as the divisor, then an ArithmeticError exception is thrown.Below program illustrates the working of intdiv in PHP:<?php  // PHP code to illustrate the working // of intdiv() Functions   $dividend = 19;$divisor = 3;   echo intdiv($dividend, $divisor);  ?>Output:6
After Seeing so far many may think that this function is equivalent tofloor($dividend/$divisor)but the example will elaborate the difference.<?php  // PHP code to differentiate between // intdiv() and floor()   $dividend = -19;$divisor = 3;   echo intdiv($dividend, $divisor) ."\n".              floor($dividend/ $divisor);  ?>Output:-6
-7
Important points to note:intdiv() Function returns the quotient of integer division.The function may raise exceptions thus the developer has to tackle edge cases.The function is not equivalent to the floor function applied to the float division or ‘/’.Reference:http://php.net/manual/en/function.intdiv.phpMy Personal Notes
arrow_drop_upSave
Below program illustrates the working of intdiv in PHP:
<?php  // PHP code to illustrate the working // of intdiv() Functions   $dividend = 19;$divisor = 3;   echo intdiv($dividend, $divisor);  ?>
Output:
6

After Seeing so far many may think that this function is equivalent to
floor($dividend/$divisor)
but the example will elaborate the difference.
<?php  // PHP code to differentiate between // intdiv() and floor()   $dividend = -19;$divisor = 3;   echo intdiv($dividend, $divisor) ."\n".              floor($dividend/ $divisor);  ?>
Output:
-6
-7

Important points to note:
intdiv() Function returns the quotient of integer division.
The function may raise exceptions thus the developer has to tackle edge cases.
The function is not equivalent to the floor function applied to the float division or ‘/’.
Reference:http://php.net/manual/en/function.intdiv.php
PHP-function
PHP-math
PHP
Web Technologies
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Insert Form Data into Database using PHP ?
How to convert array to string in PHP ?
How to Upload Image into Database and Display it using PHP ?
How to check whether an array is empty using PHP?
PHP | Converting string to Date and DateTime
Remove elements from a JavaScript Array
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?