Possible Duplicate:
Printing of Array
public function computeGHComponents()
{
error_reporting (E_ALL^ E_NOTICE);
$total = null;
$result=array();
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)
{
$result = array_merge($result,array($key=>array("Deposit"=>$value['D'],"Redemption"=>$value['W'],"Reload"=>$value['R'])));
}
print_r($result);
}
The key should be the SiteID, how can I do that?
I need this kind of output:
array ([147]=>array([Deposit] => "total amount", [Reload]=> "total amount" [Redemption]=> "total amount"))
array ([150]=>array([Deposit] => "total amount", [Reload]=> "total amount" [Redemption]=> "total amount"))
array ([3]=> array([Deposit] => "total amount", [Reload]=> "total amount" [Redemption]=> "total amount"))
the key should be the SiteID. Please revised the code :(
It is normal because you are using array_merge(), take a look at the documentation : http://php.net/manual/en/function.array-merge.php
Values in the input array with numeric keys will be renumbered with incrementing keys starting from zero in the result array.
So your SiteID which is the key will be renumbered.
Then, to keep your keys, it will be better to do this :
$result[$key] = array("Deposit"=>$value['D'], "Redemption"=>$value['W'], "Reload"=>$value['R']);