Open In App

PHP intdiv() Function

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:

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:

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:

Reference:
http://php.net/manual/en/function.intdiv.php


Article Tags :