Content · Programming · PHP

PHP intdiv() Function: Usage and Examples

Understand PHP intdiv() with three examples, return behavior, important pitfalls, and related operations.

1 views Published Oct 16, 2026 Updated Oct 16, 2026

Use intdiv() when you need to returns the integer quotient of two integers, discarding the remainder in a PHP application. The examples below show the actual operation and its limitations.

What Is intdiv() in PHP?

Returns the integer quotient of two integers, discarding the remainder. The exact signature supported by your installation depends on its PHP version and enabled extensions.

Its syntax is:

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

Parameters and return value: The parameter types, optional arguments, references, and return type are shown in the signature above. Optional parameters are marked with an ellipsis in this reference signature.

Example 1: Basic Usage

<?php

echo intdiv(10,3);

Output:

3

Example 2: Different Input or Behavior

<?php

echo intdiv(-10,3);

Output:

-3

Practical Example: Applying the Function

<?php

$items = 23; $itemsPerPage = 5; echo intdiv($items + $itemsPerPage - 1,$itemsPerPage);

Output:

5

Important Behavior and Edge Cases

Dividing by zero throws DivisionByZeroError; PHP_INT_MIN / -1 can overflow.

Comparison With Related Functions

ApproachDifference
intdiv()Returns the integer quotient of two integers, discarding the remainder.
Related operation/ returns floating-point division results; intdiv() returns an integer quotient.

Common Beginner Mistakes

MistakeCorrect Approach
Ignoring the function-specific limitationDividing by zero throws DivisionByZeroError; PHP_INT_MIN / -1 can overflow.
Confusing this function with a related operation/ returns floating-point division results; intdiv() returns an integer quotient.

Key Takeaways

  • Returns the integer quotient of two integers, discarding the remainder.
  • Dividing by zero throws DivisionByZeroError; PHP_INT_MIN / -1 can overflow.
  • / returns floating-point division results; intdiv() returns an integer quotient.

Use intdiv() for the specific operation demonstrated above. Check its prerequisites and handle failure conditions before using it with production data.

Share this resourceSend this page to someone who may find it useful.