I need to group the data in my 2d array by the SiteId column values and then use the TransactionType value within that group as the second level key which need to collect the total Amount for that transaction in the group.
Input:
[
['SiteID' => 147, 'Amount' => '500.00', 'TransactionType' => 'Deposit'],
['SiteID' => 147, 'Amount' => '500.00', 'TransactionType' => 'Redemption'],
['SiteID' => 147, 'Amount' => '1500.00', 'TransactionType' => 'Deposit'],
['SiteID' => 147, 'Amount' => '200.00', 'TransactionType' => 'Reload'],
['SiteID' => 150, 'Amount' => '100.00', 'TransactionType' => 'Deposit'],
['SiteID' => 3, 'Amount' => '500.00', 'TransactionType' => 'Redemption'],
['SiteID' => 150, 'Amount' => '200.00', 'TransactionType' => 'Redemption'],
['SiteID' => 3, 'Amount' => '500.00', 'TransactionType' => 'Deposit'],
['SiteID' => 3, 'Amount' => '200.00', 'TransactionType' => 'Deposit'],
['SiteID' => 3, 'Amount' => '200.00', 'TransactionType' => 'Reload'],
['SiteID' => 147, 'Amount' => '500.00', 'TransactionType' => 'Redemption']
]
Desired Result:
[
147 => ['Deposit' => 2000.0, 'Redemption' => 1000.0, 'Reload' => 200.0],
150 => ['Deposit' => 100.0, 'Redemption' => 200.0],
3 => ['Redemption' => 500.0, 'Deposit' => 700.0, 'Reload' => 200.0]
]
please provide a working array fragment in future.
This will produce a result like this:
Array ( [147] => Array ( [Deposit] => 2000 [Redemption] => 1000 [Reload] => 200 ) [150] => Array ( [Deposit] => 100 [Redemption] => 200 ) [3] => Array ( [Redemption] => 500 [Deposit] => 700 [Reload] => 200 ) )If you can deal with php notice warnings the loop can be shortened to: