I want to sum the values of the following array I would like to group the same items by cumulating them, the output format would also be an array
Array
(
[0] => Array
(
[0] => Array
(
[0] => R421_FD03
[1] => 1
)
[1] => Array
(
[0] => R421_FD03
[1] => 1
)
)
[1] => Array
(
[0] => Array
(
[0] => R421_FD03
[1] => 1
)
[1] => Array
(
[0] => R421_FD02
[1] => 1
)
)
)
I tested this code but the result is not the one I'm waiting for:
$sumArray = array();
array_walk_recursive($data, function($item, $key) use (&$sumArray){
$sumArray[$key] = isset($sumArray[$key]) ? $item + $sumArray[$key] : $item;
});
The result I'm waiting for is this one
Array
(
[0] => Array
(
[0] => R421_FD03
[1] => 3
)
[1] => Array
(
[0] => R421_FD02
[1] => 1
)
)
)