Examples of difference between == and === , != and !== in PHP
What is the difference between operators double equals and triple equals when they are used in IF condition in PHP ? Could you please provide an examples when are the conditions below true or false ?
IF ( $a == $b ) { }
IF ( $a === $b ) { }
IF ( $a != $b ) { }
IF ( $a !== $b ) { }
Hi,
The main difference between == and === is, that triple equals is more strict equality comparison operator than double equals. Double equals is known as an equality comparison operator and triple equals is known as an identity comparison operator.
Double equals operator returns true if both operands contain the same value. Triple equals operator returns true if both operands contain the same value and are of the same type.
123 == 123 is TRUE
123 == "123" is TRUE
123 === 123 is TRUE
123 === "123" is FALSE, because 123 is an integer and "123" is a string
123 != 123 is FALSE
123 != "123" is FALSE
123 !== 123 is FALSE
123 !== "123" is TRUE, because 123 is an integer and "123" is a string
1 answer