-2

I have data here:

Here's the result of my first function.The variable I used for the result was $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
    )
  )

Now, here's the result of my second function.The variable I used for the result was $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
            )
    )

 )

I try it with this code:

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

            }

But, I need a better result, The first one, I need to add the key of CorpAID pointing to the list of a SiteID owned by more than one AID.

Here's should be the result:

 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 
    )

Is it possible to make it? Please guide me in proper way, I appreciate your concern and Thank you in advance.

Senthil Kumar
  • 9,695
  • 8
  • 36
  • 45
Mic
  • 81
  • 2
  • 12

1 Answers1

0

At the moment you have your IDs set as children. It would be better to use these unique IDs in the keys for easier identification.

From

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

to

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

And I would change the result of the second function ($this->combined).

From

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

to

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

This would be needed afterwards

foreach($this->combined as $aid) {
  $aidID = key($aid);
  foreach($aid as $siteID) {
    $this->arrays[$siteID]['CorpAID'][] = $aidID;
  }
}
Sem
  • 4,477
  • 4
  • 33
  • 52