Home > Article > Backend Development > A brief analysis of the difference between three equal signs (===) and two equal signs (==) in PHP_PHP Tutorial
Let’s give an example first:
For example, a function of yours will return these situations:
1. Numbers greater than 0
2. Numbers less than 0
3. A number equal to 0 (that is, 0)
4. False (when failure)
At this time, if you want to capture the failure situation, you must use === instead of Use ==
because == will not only match the 4th case, but also the 3rd case, because 0 is also false!
Three equal signs mean that the types of comparison objects must also be consistent. Two equal signs indicate that the condition is satisfied as long as the values are equal.
Let’s add some more:
$a='2';//Character type 2
$b=2;//Numeric type 2
$a==$b , is correct, both are 2
$a===$b, which is incorrect because $a is character type and $b is numeric type. Although the value is the same, the type is different.
There is also the "0" mentioned in "linvo1986 - Level 6".