Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

intdiv

Performs integer division.

Available since: PHP 7.0

Syntax

intdiv(int $num1, int $num2): int

Parameters

ParameterTypeDescription
$num1intThe dividend.
$num2intThe 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
1

Regular 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

  • floor — Rounds a number down to the nearest integer.
  • round — Rounds a number to a given number of digits.

Related recipes

In the tutorial

  • Operators — Arithmetic, comparison and logical operators in PHP, and operator precedence.

Thanks for reading!

Donate to the site — we work hard for you.