What is the difference between ==
and ===
?
- How exactly does the loosely
==
comparison work? - How exactly does the strict
===
comparison work?
What would be some useful examples?
What is the difference between ==
and ===
?
==
comparison work?===
comparison work? What would be some useful examples?
An addition to the other answers concerning object comparison:
== compares objects using the name of the object and their values. If two objects are of the same type and have the same member values,
$a == $b
yields true.=== compares the internal object id of the objects. Even if the members are equal,
$a !== $b
if they are not exactly the same object.The
===
operator is supposed to compare exact content equality while the==
operator would compare semantic equality. In particular it will coerce strings to numbers.Equality is a vast subject. See the Wikipedia article on equality.