Strange behavior with isset() returning true for an Array Key that does NOT exist

前端 未结 3 1932
臣服心动
臣服心动 2020-12-12 02:05

I have the following array called $fruits:

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

            


        
3条回答
  •  無奈伤痛
    2020-12-12 03:07

    [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.

提交回复
热议问题