Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何以多维方式创建键和绑定数组值_Php_Arrays_Multidimensional Array_Array Merge - Fatal编程技术网

Php 如何以多维方式创建键和绑定数组值

Php 如何以多维方式创建键和绑定数组值,php,arrays,multidimensional-array,array-merge,Php,Arrays,Multidimensional Array,Array Merge,我这里有数据: 这是我的第一个函数的结果。我用于结果的变量是$this->array Array ( [1] => Array //Transactiondetails of SiteID 1 ( [SiteID] => 1 [Balance] => 2000 [MinBalance] => 1000 [MaxBalance] => 500 [OwnerAID] => 1

我这里有数据:

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

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 );

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

结果如下:

 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 
    )

有可能吗?请以适当的方式指导我,我感谢您的关心并提前向您表示感谢。

目前您的身份证已设置为儿童。最好在键中使用这些唯一ID,以便更容易识别

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

之后需要这样做

foreach($this->combined as $aid) {
  $aidID = key($aid);
  foreach($aid as $siteID) {
    $this->arrays[$siteID]['CorpAID'][] = $aidID;
  }
}

谁能帮帮我吗,我知道这对你们来说很容易。谢谢是的,有可能做到。问题得到了回答。下一位。
[1] => Array ( // SiteID
  ...
)
[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;
  }
}