0

intval:

Get the integer value of a variable

echo intval('1000000000000');

returns 2147483647.

Why?

Robert
  • 10,126
  • 19
  • 78
  • 130

3 Answers3

2

The size of an integer in PHP is platform-dependent. The documentation for intval() clearly explains this:

The maximum value depends on the system. 32 bit systems have a maximum signed integer range of -2147483648 to 2147483647. So for example on such a system, intval('1000000000000') will return 2147483647. The maximum signed integer value for 64 bit systems is 9223372036854775807.

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
1

From the same documentation you shared..

The maximum value depends on the system. 32 bit systems have a maximum signed integer range of -2147483648 to 2147483647. So for example on such a system, intval('1000000000000') will return 2147483647. The maximum signed integer value for 64 bit systems is 9223372036854775807.

echo intval('1000000000000');

returns 2147483647. Why?

is because the system you're trying is 32 bits system

zzlalani
  • 22,960
  • 16
  • 44
  • 73
0

Because

1. You have 32 bit systems.

2. That's why you can operate a maximum signed integer range of -2147483648 to 2147483647`.

For this value there will be no problem if You had 64 bit systems Antother example:

On 32 bit systems

echo intval('420000000000000000000'); // 2147483647

On 64 bit systems

echo intval('420000000000000000000'); // 420000000000000000000
sergio
  • 5,210
  • 7
  • 24
  • 46