Strange behavior with isset () returning true for an array key that does not exist

advertisements

I have the following array called $fruits:

Array
(
    [response] => Array
        (
            [errormessage] => banana
        )  

    [blah] => Array
        (
            [blah1] => blahblah1
            [blah2] => blahblah2
            [blah3] => blahblah3
            [blah4] => blahblah4
        )  

)

Yet when I do:

isset($fruits['response']['errormessage']['orange'])

It returns true!

What on earth would cause such a strange behavior and how can I fix this?

Thanks!


[n] is also a way to access characters in a string:

$fruits['response']['errormessage']['orange']
==
$fruits['response']['errormessage'][0] // cast to int
==
b (the first character, at position 0) of 'banana'

Use array_key_exists, possibly in combination with is_array.