我这里有数据:
Array
(
[0] => Array
(
[SiteID] => 147
[Amount] => 500.00
[TransactionType] => D
)
[1] => Array
(
[SiteID] => 147
[Amount] => 500.00
[TransactionType] => D
)
[2] => Array
(
[SiteID] => 145
[Amount] => 500.00
[TransactionType] => R
)
)
我已经完成了重新加载、赎回和存款的计算并且它正在工作,但是如果站点 ID 没有存款 [D] 或重新加载 [R] 或赎回 [W] 的交易,它应该等于 0。我的代码在这儿:
public function computeGHComponents()
{
error_reporting (E_ALL^ E_NOTICE);
foreach ($this->transaction as $t){
$amount = (float) $t['Amount'];
if (isset($this->totals[ $t['SiteID'] ][ $t['TransactionType'] ])){
$this->totals[ $t['SiteID'] ][ $t['TransactionType'] ] += (float) $amount;
} else {
$this->totals[ $t['SiteID'] ][ $t['TransactionType'] ] = (float) $amount;
}
}
foreach($this->totals as $key => $value)
{
$this->result[$key] = array("Deposit"=>$value['D'], "Redemption"=>$value['W'], "Reload"=>$value['R']);
}
print_r($this->result);
}
结果应如下所示:
Array
(
[147] => Array
(
[Deposit] => 1000
[Redemption] => 0
[Reload] => 0
)
[145] => Array
(
[Deposit] => 0
[Redemption] => 500.00
[Reload] => 0
)
)
在此先感谢,请以正确的方式指导我。