Comparing Arrays And Object

../_images/comparing-arrays.png

== and === apply different algorithms to compare arrays.

== compares keys without taking order in account, while === also takes into account the order.

== applies type juggling to values, and then compare them loosely, while === makes a identity comparison, with value and type. == and === compare keys the same way, as they can only be int or string, and no type-juggling is applied.

The same rules apply when comparing objects: the order of assignations of the properties is used by == but not by ===.

Finally, comparing an array and an object always fails: one of them has to be cast.

See Also

PHP Features