Array (
[0] => Array (
[name] => Chennai [id] => 98 )
[1] => Array (
[name] => India [id] => 99 )
[2] => Array (
[name] => South India [id] => 100 )
[3] => Array (
[name] => North India [id] => 101 )
[4] => Array (
[name] => Delhi [id] => 102 )
)
这是我的数组,我试图提取这样的数据,它显示我错误
foreach ($name as $key => $value) {
echo $value->name;
}
答案 0 :(得分:4)
您可以将循环更改为:
foreach ($name as $key => $value) {
echo $value['name'];
}
答案 1 :(得分:1)
实际上你有一个数组,同时将它作为一个对象检索。除了改变之外,你的所有代码都是完美的,
foreach ($name as $key => $value)
{
echo $value['name']; //you wrote it $value->name which is wrong
}