i have this JSON array i decode into a PHP array and would like to check how much have been sold in total in each category
[{
"categorycode": "W0000000391",
"grosssalesprice": "50.00"
},
{
"categorycode": "W0000000396",
"grosssalesprice": "170.00"
},
{
"categorycode": "W0000000391",
"grosssalesprice": "50.00"
},
{
"categorycode": "W0000000391",
"grosssalesprice": "55.00"
}]
and would like to get
{
"categorycode": "W0000000391",
"grosssalesprice": "155.00"
},
{
"categorycode": "W0000000396",
"grosssalesprice": "170.00"
}
I tried, this gives me 1 entry foreach element, but how do i append every item in this array?
foreach($jsonDecoded as $item) {
$sortedData[$item['categorycode']] = array(
'Konto' => $item['categorycode'],
'Beløb' => $item['grosssalesprice']
);
}