Possible Duplicate:
How do the equality (== double equals) and identity (=== triple equals) comparison operators differ?
I know the basic difference between ==
and ===
, but can some experienced coders tell me some practical examples for both cases?
==
checks if the values of the two operands are equal or not. ===
checks the values as well as the type of the two operands.
if("1" == 1)
echo "true";
else
echo "false";
The above would output true
.
if("1" === 1)
echo "true";
else
echo "false";
The above would output false
.
if("1" === (string)1)
echo "true";
else
echo "false";
The above would output true
.
Easiest way to display it is with using strings. Two examples:
echo ("007" === "7" ? "EQUAL!" : "not equal");
echo ("007" == "7" ? "EQUAL!" : "not equal");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With