Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I group arrays in a one big array in PHP
    primarykey
    data
    text
    <p>I have data here:</p> <pre><code>Array ( [3] =&gt; Array ( [SiteID] =&gt; 3 [Balance] =&gt; 94000.99 [MinBalance] =&gt; 100000.00 [MaxBalance] =&gt; 500000.00 [OwnerAID] =&gt; 17 [GroupID] =&gt; 1 [Deposit] =&gt; 459000 [Redemption] =&gt; 703576 [Reload] =&gt; 169100 ) [2] =&gt; Array ( [SiteID] =&gt; 2 [Balance] =&gt; 19000.00 [MinBalance] =&gt; 100000.00 [MaxBalance] =&gt; 1000000.00 [OwnerAID] =&gt; 83 [GroupID] =&gt; 1 [Deposit] =&gt; 1500 [Redemption] =&gt; 1000 [Reload] =&gt; 1000 ) [139] =&gt; Array ( [SiteID] =&gt; 139 [Balance] =&gt; 855100.00 [MinBalance] =&gt; 100000.00 [MaxBalance] =&gt; 1000000.00 [OwnerAID] =&gt; 23 [GroupID] =&gt; 1 [Deposit] =&gt; 0 [Redemption] =&gt; 0 [Reload] =&gt; 0 ) ) </code></pre> <p>I need to group this arrays in to two groups: First group - all OwnerAID owning one SiteID and the Second group all OwnerAID owning more than one SiteID. Is it possible to make it? The result should be shown like this:</p> <p>here's the group of OwnerAID owning one SiteID in a one big array:</p> <pre><code>Array ( [17] =&gt; Array ( [Sites] =&gt; Array ( [0] =&gt; Array ( [SiteID] =&gt; 3 [Balance] =&gt; 94000.99 [MinBalance] =&gt; 100000.00 [MaxBalance] =&gt; 500000.00 [OwnerAID] =&gt; 17 [GroupID] =&gt; 1 [Deposit] =&gt; 459000 [Redemption] =&gt; 703576 [Reload] =&gt; 169100 ) ) ) } </code></pre> <p>while here, OwnerAID owning more than one SiteID in another one big array: </p> <pre><code>Array ( [83] =&gt; Array ( [Sites] =&gt; Array ( [0] =&gt; Array ( [SiteID] =&gt; 2 [Balance] =&gt; 19000.00 [MinBalance] =&gt; 100000.00 [MaxBalance] =&gt; 1000000.00 [OwnerAID] =&gt; 83 [GroupID] =&gt; 1 [Deposit] =&gt; 1500 [Redemption] =&gt; 1000 [Reload] =&gt; 1000 ) [1] =&gt; Array ( [SiteID] =&gt; 149 [Balance] =&gt; 150000.00 [MinBalance] =&gt; 100000.00 [MaxBalance] =&gt; 250000.00 [OwnerAID] =&gt; 83 [GroupID] =&gt; 1 [Deposit] =&gt; 0 [Redemption] =&gt; 0 [Reload] =&gt; 0 ) ) ) </code></pre> <p>Someone suggest me this code but I already modified it, I do some research to modify this code. Please help me to accomplish this kind of result. Please be patient in answering my question, I'm just a beginner in a world of programming in PHP.here's the code:</p> <pre><code>public function groupIndividualAndAggregateSites() { $owners = array(); foreach($this-&gt;combined as $key =&gt; $value) { $owner_id = $value['OwnerAID']; $site_id = $value['SiteID']; if (array_key_exists($owner_id,$owners)) { // He has one or more sites already? if(is_array($owners[$owner_id])) { array_push($owners[$owner_id],$site_id); } else { // User already has one site. // Make an array instead and add old and new siteID $old_site_id = $owners[$site_id]; $owners[$owner_id] = array_merge((array)$value, array($old_site_id)); } } else { $owners[$owner_id] = array($value,'Sites'=&gt; array($site_id)); } } print_r($owners); } </code></pre> <p>Please help me, and Thank you in advance. I hope someone could help me to come up with this kind of result. Please guide me in proper way.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload