I need to flatten a multidimensional array to form an associative array of unique values and their sums.
My sample array:
[
[
'winners' => [
'Gold Member',
'CROTCH SNIFFER',
'TEAM #1'
],
'prizeTotal' => 20
],
[
'winners' => [
'TEAM #1',
'CROTCH SNIFFER'
],
'prizeTotal' => 60
],
[
'winners' => [
'Gold Member',
'TEAM #1'
],
'prizeTotal' => 30
],
[
'winners' => [
'TEAM #1',
'TEAM #2',
'SCREW-NUT-BOLT'
],
'prizeTotal' => 90
]
]
Please forgive the names...it's not my DB.
In each data set, the prizeTotal is awarded to each value in the winners subarray.
How can I group the winners values and sum their respective prizeTotal values?
Desired result:
array (
'Gold Member' => 50,
'CROTCH SNIFFER' => 80,
'TEAM #1' => 200,
'TEAM #2' => 90,
'SCREW-NUT-BOLT' => 90,
)