Można spróbować
$data = array(
0 => array(
'event' => 'Conference',
'budget' => 3700,
),
1 => array(
'event' => 'Conference',
'budget' => 500,
),
2 => array(
'event' => 'Showroom',
'budget' => 1000,
),
3 => array(
'event' => 'Mission Chez client',
'budget' => 2000,
),
4 => array(
'event' => 'Séminaire',
'budget' => 700,
),
5 => array(
'event' => 'Livraison',
'budget' => 4000,
),
6 => array(
'event' => 'Conference',
'budget' => 334,
),
);
$sum = array_reduce($data, function ($a, $b) {
isset($a[$b['event']]) ? $a[$b['event']]['budget'] += $b['budget'] : $a[$b['event']] = $b;
return $a;
});
print_r(array_values($sum));
wyjściowy
Array
(
[0] => Array
(
[event] => Conference
[budget] => 4534
)
[1] => Array
(
[event] => Showroom
[budget] => 1000
)
[2] => Array
(
[event] => Mission Chez client
[budget] => 2000
)
[3] => Array
(
[event] => Séminaire
[budget] => 700
)
[4] => Array
(
[event] => Livraison
[budget] => 4000
)
)
Zachowuje drugi klucz "budżet", ale nie pierwsze "zdarzenie", daje to: [link] (http://d.pr/i/7rKM) – Alucard
Naprawdę muszę zachować tę samą strukturę, ale wartości sumy z tym samym kluczem – Alucard
Zobacz Zaktualizowany kod – Baba