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 ) { }
0
give a positive ratinggive a negative rating
18 Apr 2020 at 06:56 PM
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
0
give a positive ratinggive a negative rating
19 Apr 2020 at 02:06 PM
Tim
Share on FacebookShare on TwitterShare on LinkedInSend email
x
x
2024 AnswerTabsTermsContact us