【发布时间】:2015-06-23 20:13:10
【问题描述】:
我的关联数组:
$products = array();
$products[101] = array(
"name" => "Red Shirt",
"img" => "img/shirts/shirt-101.jpg",
"price" => 18
);
$products[102] = array(
"name" => "Black Shirt",
"img" => "img/shirts/shirt-102.jpg",
"price" => 20
);
$products[103] = array(
"name" => "Blue Shirt",
"img" => "img/shirts/shirt-103.jpg",
"price" => 20
);
假设我想像这样输出所有产品数组的名称:
红衬衫、黑衬衫、蓝衬衫
如何使用 foreach 循环实现这一点?我试图一次只从所有数组中输出一个特定的键,但如果不输出所有键,我似乎无法做到这一点。
还可以说我只想输出某个数组的“价格”,例如 $products[103] 我该如何实现?
谢谢!
【问题讨论】:
标签: php loops foreach associative-array