First post, leave master
I took a five-dimensional array from Redis and I needed to process the addition, as follows
$a = Array (0 = = Array (0=> array ("date" = "201201", "area" = = Array (click + = "3", traffic = "+")),1=> Array ("Date" and "201202", "area" = = Array (click + = "8", traffic = "" + "),8=> ar Ray (Click + = "5", traffic = ""))), 1 = = Array ("date" = "201201", "area" = = = Array (arr. Ay (click + = "9", Traffic "+"),8=> Array (click = "6", traffic = "20120")),1=> Array ("date" and "=") 2 "," area "= NULL));
Hope that after the data processing, the same date premise, the same key in the area corresponding to the click and traffic values, namely 0 and 1 of the two large arrays, date 201001, and area 12 corresponding to the click and traffic processing should be 12 and 50, 8 corresponds to 6 and 60, and other analogy, to seek the traversal or other methods to deal with success, thank you!
Reply to discussion (solution)
What is the final result? Put it on.
The results are as follows, thanks for attention
$a = Array (0 = = Array ( 0=> Array ( "date" = "201201", "area" = = Array ( C5/>click = "A", traffic = "6" ),8=> Array ( click + = "+", traffic "+" )
) ), 1=> Array ( "date" = "201202", "area" = = Array ( click = > "8", traffic = "+" ), 8=> Array ( click + = "5", traffic = " " ") ) ) ) );
$t = Array (), foreach ($a as $k = = $v) {foreach ($v as $k 1=> $v 1) {$t [0][$k 1][' date '] = $v 1[' Date '];foreach ($v 1[' area '] a S $k 2=> $v 2) {$t [0][$k 1][' area '] [$k 2][' click '] + = $v 2[' click ']; $t [0][$k 1][' area '] [$k 2][' traffic '] + = $v 2[' Traffic ' ];}}} echo "";p Rint_r ($t); echo"";
The results are as follows:
Array ([0] = = Array ([0] = = Array ([Date] = 201201 [Area] = = Array ([+] = array ([click] = [Traffic] = 50 ) [8] = = Array ( [Click] = 6 [traffic] + 60) )) [1] = = Array ([Date] = 201 202 [Area] = = Array ([+] = array ([Click] = 8 [traffic] => ; 40 ) [8] = = Array ( [Click] = 5 [traffic] + 50) ) ) ))
Thank you for the four floor positive solution