我无法使用 PHP 访问数组的更深层部分并在页面上以某种方式显示它。
我试图用一个城市和一个计数来显示这样的数据:
Mobile (3)
Auburn (2)
这是我的数组:
Array
(
[0] => Array
(
[0] => Array
(
[city] => Mobile
[numLocations] => 3
)
[1] => Array
(
[city] => Auburn
[numLocations] => 2
)
)
)
这是我到目前为止所拥有的。这仅显示“数组”一词。
while($row = mysqli_fetch_assoc($result)){
$state = $row['state'];
$stateAbv = $row['stateAbv'];
$city = $row['city'];
$numSLocations = $values['cnt'];
if (!isset($rows[$row['state']])){
$rows[$row['state']] = array();
}
$rows[$row['state']][] = ['city' => $city, 'numLocations' => $numLocations];
}
foreach($rows as $state => $cities){
echo array_column($cities, 'numLocations'));
}
喵喵时光机
莫回无