"201201","area"=> array(12 => array(cli">
时间:2021-07-01 10:21:17 帮助过:16人阅读
$a = array( 0 => array( 0=> array( "date" => "201201", "area"=> array( 12 => array( click => "3", traffic => "30" ) ) ), 1=> array( "date" => "201202", "area"=> array( 12 => array( click => "8", traffic => "40" ), 8=> array( click => "5", traffic => "50" ) ) ) ), 1 => array( 0=> array( "date" => "201201", "area"=> array( 12 => array( click => "9", traffic => "20" ), 8=> array( click => "6", traffic => "60" ) ) ), 1=> array( "date" => "201202", "area" => NULL ) ), );
最后结果是怎么样的? 贴一下。
结果如下,感谢关注
$a = array( 0 => array( 0=> array( "date" => "201201", "area"=> array( 12 => array( click => "12", traffic => "50" ) , 8=> array( click => "6", traffic => "60" ) ) ), 1=> array( "date" => "201202", "area"=> array( 12 => array( click => "8", traffic => "40" ), 8=> array( click => "5", traffic => "50" ) ) ) ) );
$t = array();foreach ($a as $k=>$v){ foreach ($v as $k1=>$v1) { $t[0][$k1]['date'] = $v1['date']; foreach ($v1['area'] as $k2=>$v2) { $t[0][$k1]['area'][$k2]['click'] += $v2['click']; $t[0][$k1]['area'][$k2]['traffic'] += $v2['traffic']; } }}echo "";print_r($t);echo "";
结果如下:
Array( [0] => Array ( [0] => Array ( [date] => 201201 [area] => Array ( [12] => Array ( [click] => 12 [traffic] => 50 ) [8] => Array ( [click] => 6 [traffic] => 60 ) ) ) [1] => Array ( [date] => 201202 [area] => Array ( [12] => Array ( [click] => 8 [traffic] => 40 ) [8] => Array ( [click] => 5 [traffic] => 50 ) ) ) ))感谢四楼正解