我有两个数组存储在单个变量中我希望通过for-each循环检索数据,问题是name
索引给出了错误。请查看以下代码。
Array
(
[name] => special
[Cat_id] => 59
)
Array
(
[singleproduct] => Array
(
[product_id] => 52
[thumb] => http://localhost/swefloraProject/upload/image/cache/catalog/birthday/home-product-01-80x80.png
[name] => gift flowers
[description] => when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has ..
[price] => $0.00
[special] =>
[tax] => $0.00
[minimum] => 1
[rating] => 0
[href] => http://localhost/Project/upload/index.php?route=product/product&product_id=52
)
)
foreach($categories as $category){
print_r($category['name']);
}
Notice: Undefined index: name in
答案 0 :(得分:0)
foreach($categories as $key=> $category){
print_r($key); // prints "name" on first iteration
print_r($category); // prints "special" on first iteration
}