A comparison of longer numeric strings
This post was last edited by Anyilaoliu on 2013-12-13 15:04:43
Title
Encounter such a problem
$a = "222111565652521142";
$b = "222111565652521139";
$c = 222111565652521142;
$d = 222111565652521139;
Var_dump ($a);
echo "
";
Var_dump ($b);
echo "
";
Var_dump ($c);
echo "
";
Var_dump ($d);
echo "
";
if ($a = = $b) {
Echo 3;
}else{
Echo 31;
}
echo "
";
if ($c = = $d) {
Echo 4;
}else{
Echo 41;
}
echo "
";
The result is
String ' 222111565652521142 ' (length=18)
String ' 222111565652521139 ' (length=18)
Float 2.2211156565252E+17
Float 2.2211156565252E+17
31
4
The question is, how does the second case compare the two?
Two sets of numbers read from the database, the Var_dump is a string (18) But the comparison is the opposite of the example above, and the comparison of two strings is also passed.
Solving
Share to: more
------Solution--------------------
Most of the PHP environments we use are 32-bit, whereas a long integer in a 32-bit environment is represented by 4 bytes.
i.e.-pow (2,31) to POW (2,31)
Pow (2,31) = 2147483648
Pow (2,32) = 4294967296
This obviously does not satisfy the general need, so PHP has done some expansion on the basis of the Logn type. 1 integers stored in 6 bytes
That is, a positive number between 99999999999999 and 99999999999999, or a 14-bit integer.
And in 64-bit PHP can easily break this limit, because 64-bit environment, a LOGN type itself is 8 bytes
------Solution--------------------
with = = = does not convert