Skip to content

PHP Tutorial Data Types

Integers

Lesson 36 of 369 2 min read By Deepak Paswan Updated Oct 5, 2026

An integer is a whole number, positive or negative, with no decimal point.

index.php
PHP
<?php
$age = 25;
$temperature = -4;
$zero = 0;

var_dump($age, $temperature, $zero);
Output
OUTPUT
int(25)
int(-4)
int(0)

Readable big numbers

You can use underscores inside a number to make it easier to read. PHP ignores them.

index.php
PHP
<?php
$population = 1_400_000_000;
echo $population;
Output
OUTPUT
1400000000

Other number systems

index.php
PHP
<?php
echo 255 . "\n";      // decimal
echo 0xFF . "\n";     // hexadecimal
echo 0b11111111 . "\n"; // binary
echo 0377 . "\n";     // octal (starts with 0)
echo 0o377;           // octal, explicit form (PHP 8.1+)
Output
OUTPUT
255
255
255
255
255

The size limit

On a 64-bit system, the biggest integer is PHP_INT_MAX.

index.php
PHP
<?php
echo PHP_INT_MAX . "\n";
echo PHP_INT_MIN;
Output
OUTPUT
9223372036854775807
-9223372036854775808

Overflow becomes a float

If a calculation goes past the limit, PHP silently switches to a float.

index.php
PHP
<?php
$big = PHP_INT_MAX + 1;
var_dump($big);
Output
OUTPUT
float(9.223372036854776E+18)

The result is no longer exact. For huge exact numbers, PHP has the bcmath and gmp extensions.

Division may give a float

index.php
PHP
<?php
var_dump(10 / 5);   // exact division gives an int
var_dump(10 / 4);   // otherwise a float
var_dump(intdiv(10, 4)); // whole-number division
Output
OUTPUT
int(2)
float(2.5)
int(2)
lightbulb
Check with is_int()
When you receive a value from a form, it arrives as a string, even if the user typed 25. Use is_numeric() or filter_var() to check it. See Numeric Validation.