-2

我这里有数据:

这是我的第一个函数的结果。我用于结果的变量是 $this->arrays。

Array
(
[1] => Array //Transactiondetails of SiteID 1
    (
        [SiteID] => 1
        [Balance] => 2000
        [MinBalance] => 1000
        [MaxBalance] => 500
        [OwnerAID] => 1
        [GroupID] => 1
        [Deposit] => 10000
        [Reload] => 0
        [Redemption] => 0
    )
  )

现在,这是我的第二个函数的结果。我用于结果的变量是 $this->combined。

Array
(
[0] => Array
    (
        [AID] => 1
        [Sites] => Array
            (
                [0] => 1 //List of SiteID owned by AID                   
                [1] => 5
            )
    )

[1] => Array
    (
        [AID] => 3
        [Sites] => Array
            (
                [0] => 4 //SiteID
            )
    )

[2] => Array
    (
        [AID] => 4
        [Sites] => Array
            (
                [0] => 1 //SiteID
            )
    )

 )

我用这段代码试试:

 public function createListOfCorpOwnedSites()
 {

 foreach ($this->combined as &$site) {

            $aids = array();

            foreach ($this->result_array as $acct) {
              if ($acct['SiteID'] === $site['SiteID'])
                $aids[] = $acct['AID'];
              }
              $site['CorpAID'] = $aids;
            }

            print_r($this->combined );

            }

但是,我需要一个更好的结果,第一个,我需要添加指向由多个 AID 拥有的 SiteID 列表的 CorpAID 的键。

结果应该是这样的:

 Array([0]=> Array(
        [SiteID] => 1
        [Balance] => 2000
        [MinBalance] => 1000
        [MaxBalance] => 500
        [OwnerAID] => 1
        [GroupID] => 1
        [Deposit] => 10000
        [Reload] => 0
        [Redemption] => 0
        [CorpAID] => Array(
                      [0] => 1
                      [1] => 4 
    )

有可能做到吗?请以正确的方式指导我,感谢您的关注,并提前感谢您。

4

1 回答 1

0

目前,您将 ID 设置为孩子。最好在密钥中使用这些唯一 ID,以便于识别

[1] => Array (
  [SiteID] => 1
  ...
)

[1] => Array ( // SiteID
  ...
)

我会改变第二个函数的结果($this->combined)。

[0] => Array (
  [AID] => 1
  ...
)

[1]=> Array ( // AID ID
  ...
)

以后需要这个

foreach($this->combined as $aid) {
  $aidID = key($aid);
  foreach($aid as $siteID) {
    $this->arrays[$siteID]['CorpAID'][] = $aidID;
  }
}
于 2012-08-21T12:28:38.370 回答