<?php
$array = array (
array( 'SiteID' => 147, 'Amount' => '500.00', 'TransactionType' => 'Deposit' ),
array( 'SiteID' => 147, 'Amount' => '500.00', 'TransactionType' => 'Redemption'),
array( 'SiteID' => 147, 'Amount' => '1500.00', 'TransactionType' => 'Deposit' ),
array( 'SiteID' => 147, 'Amount' => '200.00', 'TransactionType' => 'Reload' ),
array( 'SiteID' => 150, 'Amount' => '100.00', 'TransactionType' => 'Deposit' ),
array( 'SiteID' => 3, 'Amount' => '500.00', 'TransactionType' => 'Redemption' ),
array( 'SiteID' => 150, 'Amount' => '200.00', 'TransactionType' => 'Redemption' ),
array( 'SiteID' => 3, 'Amount' => '500.00', 'TransactionType' => 'Deposit' ),
array( 'SiteID' => 3, 'Amount' => '200.00', 'TransactionType' => 'Deposit' ),
array( 'SiteID' => 3, 'Amount' => '200.00', 'TransactionType' => 'Reload' ),
array( 'SiteID' =>147, 'Amount' => '500.00', 'TransactionType' => 'Redemption' )
);
$result = [];
foreach ($array as ['SiteID' => $id, 'Amount' => $amt, 'TransactionType' => $trn]) {
$result[$id][$trn] = ($result[$id][$trn] ?? 0) + $amt;
}
var_export($result);
- Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- array (
147 =>
array (
'Deposit' => 2000.0,
'Redemption' => 1000.0,
'Reload' => 200.0,
),
150 =>
array (
'Deposit' => 100.0,
'Redemption' => 200.0,
),
3 =>
array (
'Redemption' => 500.0,
'Deposit' => 700.0,
'Reload' => 200.0,
),
)
preferences:
69.56 ms | 407 KiB | 5 Q