Differences in usage of congruent (= = =) and equality (= =) in PHP
Let's take a look at the following program: $STR = "0d52"; If (0== $str) {echo "true"} Else {echo "false"}
The result of this program running unexpectedly, "0d52" actually by PHP think and 0 equal. Why is there such a situation? The execution of the relational operation "= =" requires that the data types on both sides of the operator must be identical, so that the string to the right of the equal sign is cast for integral type 0.
This is the disadvantage of many weakly typed languages. This kind of mistake is not tolerated in our procedure, is there any way to solve this problem? The answer, of course, is yes, and in PHP we are provided with all equal to solve similar problems.
Now we're going to rewrite the program into the following form to explain how all equals works. $str = "0d52"; If (0=== $str) {echo "true"} Else {echo "false"}
All equal to the operation process is as follows: 1. Determine if the data type is equal to the operator 2 edge if it is not the same, then return False 2. Determines whether the values of all equals operator 2 are equal and returns false 3 if not equal. Finally, the above 2 steps are performed and manipulated. Returns the result of the operation.
Not all equal to the operation process is exactly equal to the opposite: 1. The judgment is not equal to the same as the data type of the operator 2 edge if it is not the same, True 2 is returned. The judgment is not equal to the value of the 2 side of the operator, or true 3 if not equal. Finally, the above 2 steps are performed or manipulated. The result of the return or operation.
All right, PHP is equal to not all equal to the completion of the explanation, I hope that the reader of PHP enthusiasts have benefited!
The above describes the php equality = = = and Equal = = usage differences, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.