Comparison of long numeric strings This post was last edited by anyilaoliu from 2013-12-1315: 04: 43 such as Question & nbsp; encountered such a problem $ a & nbsp; 222111565652521142; $ B & nbsp; 222111565652521139; $ c & nbsp; & nbs long numeric string comparison problem
This post was last edited by anyilaoliu at 15:04:43, January 13 ,.
Example
This problem occurs.
$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 can we compare the two in the second case?
Problem 2: The two groups of numbers read from the database are displayed as string (18) after var_dump, but the comparison result is the opposite of the above example, the comparison between the two strings is also passed.
Solution
Share: More
------ Solution --------------------
Most of the php environments we use are 32-bit, while in a 32-bit environment, a long integer is represented in 4 bytes.
That is, between-pow () and pow ()
Pow (2147483648) =
Pow (4294967296) =
This obviously cannot meet general requirements, so php has made some extensions based on the logn type. 6 bytes are used to store one integer.
That is, a positive number between-99999999999999 and 99999999999999, that is, a 14-digit integer.
In 64-bit php, this limit can be easily broken through, because in a 64-bit environment, a logn type itself is 8 bytes.
------ Solution --------------------
No conversion with ===