PHP – Difference between == (equal) and === (identical)

I had the following in my code:

$mixed = array();
$mixed[0] = "It's a zero!";
$mixed['word'] = "It's a word!";   

foreach ($mixed as $key => $value) {
  if ($key == 'word') {             
    echo $value.'<br />';

The above would for some reason print both “It’s a zero!” and “It’s a word!”. I was expecting it to print only “It’s a word!”. Why is that?? I feel like I am missing something important. When I was using === in the if statement, it worked as expected, in other words it printed only “It’s a word!”. I know there’s a difference between the equal and identical operators, but the first example is not equal is it?

Leave a Reply


Hire Me
Follow Me!
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.