Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

echo vs echo intval PHP

Tags:

php

Please can some one explain the result differences below

echo intval(1e10); 

Output 1410065408

echo 1e10; 

Output 10000000000

like image 665
Daric Avatar asked Jul 29 '26 05:07

Daric


1 Answers

A signed integer has a maximum value. On 32-bit systems, that's 2^16 or 2147483647. When intval-ing a number that's larger, it will overflow. The value you found can also calculated:

php > echo 1e10 % (2147483647);
1410065408
like image 97
Bart Friederichs Avatar answered Jul 30 '26 19:07

Bart Friederichs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!