Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8389347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:42:09+00:00 2026-06-09T18:42:09+00:00

I have data here: Array ( [3] => Array ( [SiteID] => 3 [Balance]

  • 0

I have data here:

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

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

    [139] => Array
    (
        [SiteID] => 139
        [Balance] => 855100.00
        [MinBalance] => 100000.00
        [MaxBalance] => 1000000.00
        [OwnerAID] => 23
        [GroupID] => 1
        [Deposit] => 0  
        [Redemption] => 0 
        [Reload] => 0 
    )
)

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:

here’s the group of OwnerAID owning one SiteID in a one big array:

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

while here, OwnerAID owning more than one SiteID in another one big array:

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

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:

public function groupIndividualAndAggregateSites() 
{
    $owners = array();
    foreach($this->combined as $key => $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'=> array($site_id));
        }
    }
    print_r($owners); 
}

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:42:11+00:00Added an answer on June 9, 2026 at 6:42 pm

    This returns exactly what you want.

        <?php
    
    //Array declaration
        $arr = Array
        (
            3 => Array
            (
                "SiteID" => 3,
                "Balance" => 94000,
                "MinBalance" => 100000.00,
                "MaxBalance" => 500000.00,
                "OwnerAID" => 17,
                "GroupID" => 1,
                "Deposit" => 459000,
                "Redemption" => 703576,
                "Reload" => 169100,
            ),
    
            2 => Array
            (
                "SiteID" => 2,
                "Balance" => 19000.00,
                "MinBalance" => 100000.00,
                "MaxBalance" => 1000000.00,
                "OwnerAID" => 83,
                "GroupID" => 1,
                "Deposit" => 1500,
                "Redemption" => 1000,
                "Reload" => 1000,
            ),
    
            139 => Array
            (
                "SiteID" => 139,
                "Balance" => 855100.00,
                "MinBalance" => 100000.00,
                "MaxBalance" => 1000000.00,
                "OwnerAID" => 83,
                "GroupID" => 1,
                "Deposit" => 0,
                "Redemption" => 0 ,
                "Reload" => 0 
            ),
          );
    
    
    //End of declaration;
    //Too lazy for other comments, sorry xD
    
    
        foreach ($arr as $key => $value) {
            $Newarr[$value["OwnerAID"]][] = $value; 
        }
        foreach ($Newarr as $key => $value) {
            foreach ($value as $key2 => $value2) {          
            if (count($value) == 1)
                $arrOneSite[$value2["OwnerAID"]]["Sites"][] = $value2;
                else    
                    $arrMoreThenOneSite[$value2["OwnerAID"]]["Sites"][] = $value2;
            }
        }
    
        echo "<pre>";
        print_r($arrOneSite);
        print_r($arrMoreThenOneSite);
        ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have data here: Array ( [1] => Array ( [SiteID] => 1 [OwnerAID]
I have data here: Array ( [0] => Array ( [SiteID] => 147 [Amount]
I have two data here: The result of this first function: Array ( [2]
I have data here: First, the result of my first function named getsiteaccounts() Array
I have an data array(All value of Array A are string ) : Here
So here's the problem. I have data in a MySQL DB as text. The
I have a outsource data from : http://example.com/data/news.json Here is the example result after
Here's the problem: I have a data-bound list of items, basically a way for
Here's the issue: I have 2 data contexts that I would like to do
I have hourly weather data. I've seen the function examples from here: http://casoilresource.lawr.ucdavis.edu/drupal/node/991 I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.