Ignoring the special libraries that allow you to work with very numbers, what's the largest int you can store in PHP?
Ah I found it: 232 - 1 (2147483647)
Integer overflow
If PHP encounters a number beyond the bounds of the integer type, it will be interpreted as a float instead. Also, an operation which results in a number beyond the bounds of the integer type will return a float instead.
<?php
$large_number = 2147483647;
var_dump($large_number);
// output: int(2147483647)
$large_number = 2147483648;
var_dump($large_number);
// output: float(2147483648)
The size of PHP ints is platform independent:
The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). PHP does not support unsigned integers. Integer size can be determined using the constant PHP_INT_SIZE, and maximum value using the constant PHP_INT_MAX since PHP 4.4.0 and PHP 5.0.5.
PHP 6 adds "longs" (64 bit ints).
It depends on your OS, but 2147483647 is the usual value, according to the manual.
From the PHP manual:
The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). PHP does not support unsigned integers. Integer size can be determined using the constant PHP_INT_SIZE, and maximum value using the constant PHP_INT_MAX since PHP 4.4.0 and PHP 5.0.5.
32-bit builds of PHP:
- Integers can be from -2147483648 to 2147483647
64-bit builds of PHP:
- Integers can be from -9223372036854775808 to 9223372036854775807
Numbers are inclusive.
Values outside of these ranges are usually represented by floating point values, as are non-integer values within these ranges.
There are exceptions. For example, on a 32-bit build the crc32() function wraps resulting values above 2147483647 to become negative integers, which can be a gotcha when trying to create portable code as a 64-bit build returns them as positive integers.
PHP has no support for "unsigned" integers as such.