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. 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.