When comparing two arrays (in PHP), what is the difference between == and === ?

Wish happy independence day to all Indians.

I have not posted anything since a long time. I thought to break the silence with this small post.

I was appearing for a skill test in Advanced PHP. I scored 82% (though I was expecting to get 90%), but I am upset as the percentile is just 72%. During the skill test, I found many tricky questions. But I am discussing about this particular thing, as I did not found anyone discussing this on the Internet.

Question: When comparing two arrays (in PHP), what is the difference between == and === ?

There are few confusing options for the multiple choice question. I forgot those. But if you try to guess one answer, you will be confused. Let’s understand the concept.

== is the “Equal” comparison operator. It returns TRUE if $a is equal to $b after type juggling.

=== is the “Identical” comparison operator. It returns TRUE if $a is equal to $b, and they are of the same type. (introduced in PHP 4)

As both are arrays to be compared, then both == and === will return the same result. So == and === will behave in a similar way here.


Posted

in

by

Tags:

Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.