An integer is a whole number, positive or negative, with no decimal point.
<?php
$age = 25;
$temperature = -4;
$zero = 0;
var_dump($age, $temperature, $zero);
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.
<?php
$population = 1_400_000_000;
echo $population;
1400000000
Other number systems
<?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+)
255
255
255
255
255
The size limit
On a 64-bit system, the biggest integer is PHP_INT_MAX.
<?php
echo PHP_INT_MAX . "\n";
echo PHP_INT_MIN;
9223372036854775807
-9223372036854775808
Overflow becomes a float
If a calculation goes past the limit, PHP silently switches to a float.
<?php
$big = PHP_INT_MAX + 1;
var_dump($big);
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
<?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
int(2)
float(2.5)
int(2)
Check with is_int()
25. Use is_numeric() or filter_var() to check it. See Numeric Validation.