1
兩個函數的結果結合我這裏有兩個功能:如何使用數組在PHP
public function bindOwnerToSites(){
error_reporting (E_ALL^ E_NOTICE);
foreach($this->balance as $keysaa =>$key_valuesa)//getsitebalance
{
foreach($this->sites as $keys=>$key_values)//getsites
{
if ($key_values['SiteID'] == $key_valuesa['SiteID'])
{
$this->arrays[$key_valuesa['SiteID']] = array('SiteID'=>$key_valuesa['SiteID'],'Balance'=>$key_valuesa['Balance'],'MinBalance'=>$key_valuesa['MinBalance'],'MaxBalance'=>$key_valuesa['MaxBalance'],'OwnerAID'=>$key_values['OwnerAID'],'GroupID'=>1);
}
}
}
print_r ($this->arrays,$return=null);
}
bindOwnerToSites()這個樣子的輸出:
Array
(
[1] => Array
(
[SiteID] => 1
[Balance] => 2000
[MinBalance] => 1000
[MaxBalance] => 500
[OwnerAID] => 1
[GroupID] => 1
)
)
下面是該代碼第二個功能:
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);
}
而computeGHComponents()的輸出如下所示:
Array
(
[1] => Array
(
[Deposit] => 10000
[Redemption] => 500.00
[Reload] => 200.00
)
)
現在,我需要的兩個函數的結果綁定,我會嘗試對我自己的,但有什麼錯我的代碼,我需要你們的幫助,我把這裏的一切,所以我希望你應該知道我想要達到的。這裏是我的代碼綁定:
public function bindGHComponentsToSites()
{
error_reporting (E_ALL^ E_NOTICE);
$combined = array();
foreach($this->arrays as $key => $key_value){
foreach($this->result as $keys => $key_values){
$combined[$key_values['SiteID']] = array_merge((array)$key_value, (array)$key_values);
}
}
print_r($combined);
}
結果應該是這樣的,我怎麼能有這種結果?我需要你對這個問題的耐心,我只是一個初學者程序員,所以希望你明白。
Array
(
[1] => Array
(
[SiteID] => 1
[Balance] => 2000
[MinBalance] => 1000
[MaxBalance] => 500
[OwnerAID] => 1
[GroupID] => 1
[Deposit] => 10000.00
[Redemption] => 500.00
[Reload] => 200.00
)
)
在此先感謝,請以正確的方式指導我。
尼科嗨,你」對我來說這是一個非常棒的幫助,我學到了新的東西。非常感謝。 – Mic 2012-08-11 13:42:24