I have read a lot of answers here on SO but havent been able to sort this out.
I have multidimensional array that looks like this:
Array
(
[0] => Array
(
[0] =>
[1] => 655
)
[1] => Array
(
[0] => IT-82
[1] => 14
)
[2] => Array
(
[0] => IT-21
[1] => 5
)
[3] => Array
(
[0] => IT-82
[1] => 7
)
[4] => Array
(
[0] =>
[1] => 3
)
[5] => Array
(
[0] => IT-21
[1] => 4
)
[6] => Array
(
[0] =>
[1] => 3
)
[7] => Array
(
[0] => IT-21
[1] => 3
)
[8] => Array
(
[0] => IT-72
[1] => 7
)
[9] => Array
(
[0] => IT-75
[1] => 22
)
[10] => Array
(
[0] => IT-75
[1] => 3
)
)
I would like to sum the values according to the keys ending with a single array like:
Array
(
=> 661
IT-82 => 21
IT-21 => 12
IT-82 => 12
IT-72 => 7
IT-75 => 25
)
Tried with
foreach ($array as $k=>$subArray) {
foreach ($subArray as $id=>$value) {
$sumArray[$id]+=$value;
}
}
but this only returned the sum of all the values.
Any help appreciated.