0

我这里有两个数据:

第一个函数的结果:

Array
(
[2] => Array
    (
        [SiteID] => 2
        [Balance] => 19000.00
        [MinBalance] => 100000.00
        [MaxBalance] => 1000000.00
        [OwnerAID] => 83
        [GroupID] => 1
    )

 [3] => Array
    (
        [SiteID] => 3
        [Balance] => 94000.99
        [MinBalance] => 100000.00
        [MaxBalance] => 500000.00
        [OwnerAID] => 17
        [GroupID] => 1
    )

[4] => Array
    (
        [SiteID] => 4
        [Balance] => 1000000.00
        [MinBalance] => 100000.00
        [MaxBalance] => 1000000.00
        [OwnerAID] => 12
        [GroupID] => 1
    )

)

第二个函数的结果:

 Array
(
 [3] => Array
    (
        [Deposit] => 459000
        [Reload] => 169100
        [Redemption] => 703576
    )

[2] => Array
    (
        [Deposit] => 1500
        [Reload] => 1000
        [Redemption] => 1000
    )
 )

现在,我需要绑定两个函数的结果,我尝试使用以下代码:

    public function bindGHComponentsToSites()
    {
   error_reporting (E_ALL^ E_NOTICE);  
   $combine = array();

     foreach ($this->arrays as $keys => $data) {


       foreach($this->result as $keyss => $value){

            if($data['SiteID'] == $keyss){

                $merged = array_merge((array)$data, (array)$value);

            }
             else if ($data['SiteID'] != $keyss){

                 $val = array('Deposit'=>0, 'Reload'=>0, 'Redemption'=>0);

                 $merged = array_merge((array)$data, (array)$val);
             }

        }

              $this->combined[$data['SiteID']] = $merged;

     } 

      print_r($this->combined);
  }   

但是,我得到了错误的输出,条件是,如果 bindownertosites 的 SiteID 与 Computeghcomponents 的 SiteID 不匹配,那么只需打印 Deposit、Reload 和 Redemption 的值应该为零。

存款、充值和赎回都为零,这是错误的。这应该是正确的结果:

Array
(
[2] => Array
    (
        [SiteID] => 2
        [Balance] => 19000.00
        [MinBalance] => 100000.00
        [MaxBalance] => 1000000.00
        [OwnerAID] => 83
        [GroupID] => 1
        [Deposit] => 1500
        [Reload] => 1000
        [Redemption] => 1000
    )

[3] => Array
    (
        [SiteID] => 3
        [Balance] => 94000.99
        [MinBalance] => 100000.00
        [MaxBalance] => 500000.00
        [OwnerAID] => 17
        [GroupID] => 1
        [Deposit] => 459000
        [Reload] => 169100
        [Redemption] => 703576
    )

[4] => Array
    (
        [SiteID] => 3
        [Balance] => 94000.99
        [MinBalance] => 100000.00
        [MaxBalance] => 500000.00
        [OwnerAID] => 17
        [GroupID] => 1
        [Deposit] => 0
        [Reload] => 0
        [Redemption] => 0
    )
  )

有可能得到这样的结果吗?请帮帮我,我已经处理了将近一个星期,但我总是得到错误的输出。感谢您的回复。我把所有东西都放在这里是为了澄清这些事情。请在回答之前查看我的问题。请帮助我并以正确的方式指导我。先感谢您。

4

1 回答 1

0

这将达到您的预期,如此简单

尝试

foreach (array_keys($this->arrays) as $value) {
    $default = array('Deposit' => 0, 'Reload' => 0, 'Redemption' => 0);
    if (array_key_exists($value, $this->result)) {
        $temp = array_merge($this->arrays[$value], $this->result[$value]);
        $this->arrays[$value] = $temp;
    } else {
        $temp = array_merge($this->arrays[$value], $default);
        $this->arrays[$value] = $temp;
    }
}
print_r($this->arrays);
于 2012-08-17T05:08:52.083 回答