[ create a new paste ] login | about

Link: http://codepad.org/lCCXHjKR    [ raw code | output | fork ]

PHP, pasted on Jun 13:
<?php

	$arrays[] = array(
	  0=>111, //id
	  1=>5,   //value to ad
	  2=>3   //value to ad
	);
	$arrays[] = array(
	  0=>111,
	  1=>3,
	  2=>7   
	);
	$arrays[] = array(
	  0=>111,
	  1=>2,
	  2=>1   
	);
	$arrays[] = array(
	  0=>222,
	  1=>5,
	  2=>3   
	);
	
	foreach ($arrays as $array) $final[$array[0]] = array(@$final[$array[0]][0] + $array[1], @$final[$array[0]][1] + $array[2]);
	
	var_dump($final);

?>


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
array(2) {
  [111]=>
  array(2) {
    [0]=>
    int(10)
    [1]=>
    int(11)
  }
  [222]=>
  array(2) {
    [0]=>
    int(5)
    [1]=>
    int(3)
  }
}


Create a new paste based on this one


Comments: