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 ) { }
posted on 18.04.2020 at 18:56
0pnshow more
StorStor
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
posted on 19.04.2020 at 14:06
0pnshow more
TimTim
share on facebookshare on twitter
2020 AnswerTabsTermsContact us
This site uses cookies to improve your experience, for analytics and ads. By continuing to browse this site you agree to our use of cookies.