[英]PHP array undefined index notice
When I print an array with 当我用
print_r($item)
I get a result 我得到结果
Array(
[First Name] => Sam
[Gender] => 2
[Last Name] => Smith
)
But when I do echo $item['First Name']
I receive PHP notice undefined index. 但是当我echo $item['First Name']
我收到PHP通知未定义的索引。 Why does it happen? 为什么会发生?
Make sure that you have this structure in the associative array: 确保在关联数组中具有以下结构:
$item = ['First Name' => 'Sam', 'Gender' => 2, 'Last Name' => 'Smith'];
echo $item['First Name'];
echo $item['First Name'];
will output: Sam
将输出: Sam
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.