我有这个数组:Array( [USA] => Array ( [0] => Array ( [Name] => Apple [Item] => Phones and Computers ) [1] => Array ( [Name] => McDonalds [Item] => Food ) ) [China] => Array ( [0] => Array ( [Name] => Lenovo [Item] => Computers ) ))我想介绍一下它,并回显count每个国家(美国和中国)的商品。所以我的尝试是这样的:foreach ($arr as $key => $value) { echo count($arr[$value]); echo '<br />'; foreach ($value as $subkey => $subvalue) { echo $value." -> ".$subvalue['Name']." make ".$subvalue['Item']."<br />"; }}
1 回答
ABOUTYOU
TA贡献1812条经验 获得超5个赞
你可以这样做:
foreach ($arr as $country => $companies) {
echo $country . " has " . count($companies) . " item <br />";
foreach ($companies as $k => $company) {
echo $company['Name'] . " make " . $company['Item']."<br />";
}
}
为变量保留有意义的名称可以使生活更加轻松
- 1 回答
- 0 关注
- 156 浏览
添加回答
举报
0/150
提交
取消