【发布时间】:2012-04-26 04:12:32
【问题描述】:
我无法解决这个问题...我有一个看起来像这样的数组:
Array
(
[0] => Array
(
[0] => 20120412
[1] => United States
[2] => Illinois
[3] => Marion
[4] => 2
)
[1] => Array
(
[0] => 20120412
[1] => United States
[2] => Illinois
[3] => Carbondale
[4] => 2
)
[2] => Array
(
[0] => 20120412
[1] => United States
[2] => Illinois
[3] => Carbondale
[4] => 2
)
)
我希望它是这样的:
array("United States" => array("Illinois" => array("Carbondale" => "4")));
这样它会先取出国家,然后取出州,然后将城市的所有数字相加。
到目前为止,我只有:
foreach($location_google_data3 as $location_google_data4){
if($location_google_data4[0]==date("Ymd")){
$today_visitsbycountry[$location_google_data4[1]]+=$location_google_data4[4];
}
}
这给了我一个包含国家和访问次数的数组,以便我以后可以遍历它,但不知道如何继续其余的。
【问题讨论】:
-
如果不需要日期值,建议先去掉。还有你到目前为止做了什么?请发布您的代码,否则请先做好功课。
-
抱歉,我已经添加了我拥有的代码...我还可以更改索引以获取州或城市数组,但不知道如何将它完全拼凑起来。
标签: php multidimensional-array foreach