我有以下数组叫$fruits:
Array
(
[response] => Array
(
[errormessage] => banana
)
[blah] => Array
(
[blah1] => blahblah1
[blah2] => blahblah2
[blah3] => blahblah3
[blah4] => blahblah4
)
)
然而当我这样做时:
isset($fruits['response']['errormessage']['orange'])
它返回true!
究竟是什么导致这种奇怪的行为,我该如何解决这个问题呢?
谢谢!
解决方法:
[n]也是一种访问字符串中字符的方法:
$fruits['response']['errormessage']['orange']
==
$fruits['response']['errormessage'][0] // cast to int
==
b (the first character, at position 0) of 'banana'
使用array_key_exists,可能与is_array结合使用.
标签:isset,php,arrays
来源: https://codeday.me/bug/20190929/1833263.html