This is an interesting question for new php beginners & nbsp; $ id142022219860323211; & nbsp; $ id242022219860323210; & nbsp; if ($ id1 $ id2) {& nbsp; echo: The two ID cards are the same.} else {& nbsp; echo: The two ID cards are different.} It's interesting to have a look at this question.
$ Id1 = "42022219860323211 ";
$ Id2 = "42022219860323210 ";
If ($ id1 = $ id2 ){
Echo "the two ID cards are the same ";
} Else {
Echo "the two ID cards are different ";
}
Theoretically
The two ID cards are different.
However, the actual output is somewhat different.
The web environment of my colleague and I both output the same ID cards.
One of my colleagues is normal. The two ID cards are different.
Both variables are printed as strings.
Is it true that php settings are different?
------ Solution ----------------------
Then use =.
------ Solution ----------------------
Print PHP_INT_MAX to see if the two numbers are beyond the integer range allowed in php.
We recommend that you use = for comparison.
------ Solution ----------------------
Seems to have found the cause.
Comparison Operators in PHP are a bit strange and prone to errors. now, comparison rules are listed:
1. when comparing the two characters in size, it compares the ASCII code of the two characters-this one is easy to understand.
2. when two strings are compared in size, they start from the first character and compare the corresponding ASCII size, as long as they start from a corresponding position, the current position character of one string is greater than the corresponding position character of the other string, that is, the size of the Two Strings is determined directly, such as 'BA'> 'Az' -- this is actually known to everyone.
The comparison between '10' and 'A' is the same. first, compare '1' and 'A' ASCII codes, which are larger than 'A.
3. when a number is compared with a string/character, the system first tries to convert the string/character to an integer/floating point type and then compare it, for example, if '12bsd' is converted to 12 and 'A' is converted to 0, you must note that the corresponding ASCII code value is not compared with the number.
In fact, the result of 'A' + 10 is also 10.
Which is easy to ignore: 0 returns true if it is compared with any string that cannot be converted to a number (operator =.
The following result is displayed:
1 var_dump ('20140901' <'a'); // result: boolean true
2 var_dump ('A' <1); // result: boolean true
3 var_dump (1 <'123'); // result: boolean true
It is a little different from conventional thinking ..