Triple equals = identity = the two expressions have same value and same type.
Double equals = equality = the two expressions have same value (when converted to same type), but may or may not have the same type.
Triple equals is the stronger condition. When triple equals is true, double equals is also true. When two things are identical, they must also be equal.
But when double equals is true, triple equals may or may not be true.
Examples
3.14 == '3.14'; // true (same value, type does not matter)
3.14 === '3.14'; // false (same value, but one is float and the other is numeric string)
0 == null; // true
0 === null; // false
Equal but not identical
These are all equal to each other:
- Zero
- Empty string
'' null- Empty array
- The boolean
false
But they are not identical to each other. Comparing any two using double equals returns true, but with triple equals it is false.
Confusing triple and double equals in conditional statements causes logical errors in PHP scripts.