0

为了清楚起见,这是输入的数据:

数组([0] => 数组([SiteID] => 147 [Amount] => 500.00 [TransactionType] => D)

[1] => Array
    (
        [SiteID] => 145
        [Amount] => 500.00
        [TransactionType] => D
    )

[2] => Array
    (
        [SiteID] => 145
        [Amount] => 500.00
        [TransactionType] => D
    )

[3] => Array
    (
        [SiteID] => 147
        [Amount] => 500.00
        [TransactionType] => D
    )

[4] => Array
    (
        [SiteID] => 146
        [Amount] => 500.00
        [TransactionType] => D
    )
[5] => Array
    (
        [SiteID] => 146
        [Amount] => 500.00
        [TransactionType] => D
    )
[6] => Array
    (
        [SiteID] => 145
        [Amount] => 500.00
        [TransactionType] => W
    )

[7] => Array
    (
        [SiteID] => 145
        [Amount] => 500.00
        [TransactionType] => W
    )

[8] => Array
    (
        [SiteID] => 146
        [Amount] => 330.00
        [TransactionType] => W
    )

[9] => Array
    (
        [SiteID] => 146
        [Amount] => 500.00
        [TransactionType] => W
    )

[10] => Array
    (
        [SiteID] => 3
        [Amount] => 500.00
        [TransactionType] => D
    )

我需要获得相同 SiteID 的所有事务的总和,它是 TransactionType。例如:

D - 存款,W - 赎回,R - 重新加载

结果:array ([147]=>array([Deposit] => 1000, [Reload]=>3000, [Redemption]=>2000))

注意:147 是 SiteID。

我需要计算相同 SiteID 的所有交易的存款、重新加载、赎回。

如果 SiteID 存在不止一次,只需添加每个周期的存款、重新加载和赎回。:)

请回复。谢谢并以正确的方式指导我!

4

2 回答 2

0

尝试这个

<?php
$array=array ("SiteID"=>array("Deposit" => 1000, "Reload"=>3000, "Redemption"=>2000));
$val=0;
foreach($array["SiteID"] as $key=>$value){
$val=$val+$value;
}
echo $val;
?>
于 2012-08-09T08:54:56.717 回答
0
$values = array(
    'Deposit' => 0,
    'Reload'       => 0,
    'Redemption' => 0
);
foreach ($array as $item) {
    $values[$item['SiteID']] += array_sum($item['SiteID']);
}
print_r($values);
于 2012-08-09T08:55:15.157 回答