I have data here:
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
)
)
I’m done computing the reload, redemption and deposit and it’s working, but If ever the siteID don’t have a transaction of deposit [D] or reload [R ]or redemption [W] it should be equal to 0. my code is here:
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);
}
The result should be shown like this:
Array
(
[147] => Array
(
[Deposit] => 1000
[Redemption] => 0
[Reload] => 0
)
[145] => Array
(
[Deposit] => 0
[Redemption] => 500.00
[Reload] => 0
)
)
Thanks in advance and Please guide me in proper way.
The description is vague, there is information missing in the question.
So this is kind of a blind shot, it might be what you ask but it might as well not:
In the assignment inside the last foreach, you can add 0 as a default value: