What is the maximum value for int in PHP?

Ignoring special libraries that allow you to work with very large numbers, what is the largest int value you can store in PHP?

+100
php integer
Mar 22 '09 at 7:33
source share
8 answers

From the PHP manual:

The size of the integer depends on the platform, although the maximum value of about two billion is the usual value (it is 32 bits with a sign). PHP does not support unsigned integers. The integer size can be determined using the PHP_INT_SIZE constant, and the maximum value can be determined using the PHP_INT_MAX constant, starting with PHP 4.4.0 and PHP 5.0.5.

The maximum value for 64-bit platforms is usually around 9E18, with the exception of Windows prior to PHP 7, where it has always been 32-bit.

+105
Mar 22 '09 at 7:36
source share

32-bit PHP builds:

  • Integers can range from -2,147,483,648 to 2,147,483,647 (~ Β± 2 billion)

PHP 64-bit builds:

  • Integers can range from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (~ Β± 9 quintillion)

The rooms are included.

Note: some 64-bit builds used 32-bit integers, especially older versions of Windows for PHP

Values ​​outside these ranges are represented by floating point values, as well as non-integer values ​​in these ranges. The interpreter will automatically determine whether this switch should go to a floating point, based on whether it is impossible to represent the value of the calculation result as an integer.

PHP does not support unsigned integers as such, limiting the maximum value of all integers to the range of a "signed" integer.

+83
May 16 '10 at 4:01
source share

The size of PHP ints varies by platform :

The size of the integer is equal depending on the platform, although the maximum cost of about two billion is the usual value (this is 32 bits). PHP does not support unsigned integers. Integer size can be determined using the constant PHP_INT_SIZE and the maximum value using the constant PHP_INT_MAX with PHP 4.4.0 and PHP 5.0.5.

PHP 6 adds "longs" (64-bit ints).

+20
Mar 22 '09 at 7:36
source share

(a little late, but may be useful)

Believe only PHP_INT_MAX and PHP_INT_SIZE , this value depends on your arch (32/64 bit) and your OS ...

Any other β€œguess” or β€œclue” may be false.

+15
Dec 28 '10 at 17:11
source share

Ah, I found this: 2 32 - 1 (2147483647)

http://au2.php.net/int

Integer overflow

If PHP encounters a number outside the integer type, it will be interpreted as a floating-point number. In addition, an operation that results in a number outside the bounds of the integer type will instead return a floating point number.

<?php $large_number = 2147483647; var_dump($large_number); // output: int(2147483647) $large_number = 2147483648; var_dump($large_number); // output: float(2147483648) 
+6
Mar 22 '09 at 7:36
source share

It depends on your OS, but 2147483647 is the usual value, according to manual .

+2
Mar 22 '09 at 7:36
source share

Although the PHP_INT_* constants have been PHP_INT_* a very long time, the same MIN / MAX values ​​can be found programmatically by shifting to the left until a negative number is reached:

 $x = 1; while ($x > 0 && $x <<= 1); echo "MIN: ", $x; echo PHP_EOL; echo "MAX: ", ~$x; 
0
Mar 15 '19 at 17:22
source share

It obeys the architecture of the server running PHP. For 64-bit,

print PHP_INT_MIN. ", ". PHP_INT_MAX; productivity -9223372036854775808, 9223372036854775807

0
Jun 29 '19 at 13:14
source share



All Articles