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

  • SEARCH
  • Home
  • 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 8909007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:19:44+00:00 2026-06-15T03:19:44+00:00

How can I group this array by houseid ? Array ( [0] => stdClass

  • 0

How can I group this array by houseid ?

Array
(
    [0] => stdClass Object
        (
            [id] => 1111
            [houseid] => 58
            [price] => 2995
        )

    [1] => stdClass Object
        (
            [id] => 1112
            [houseid] => 58
            [price] => 4050
        )

    [2] => stdClass Object
        (
            [id] => 1114
            [houseid] => 60
            [price] => 1695
        )

    [3] => stdClass Object
        (
            [id] => 1115
            [houseid] => 60
            [price] => 2250
        )

    [4] => stdClass Object
        (
            [id] => 1116
            [houseid] => 60
            [price] => 2295
        )
)

i need to calculate the total price for a houseid and do some math/conditions, it would be easy if the group this array…

can i format this array to something like

Array
(
    [58] => stdClass Object(
        [0] => stdClass Object
        (
            [id] => 1111
            [price] => 2995
        )
        [1] => stdClass Object
        (
            [id] => 1112
            [houseid] => 58
            [price] => 4050
        )
    )
    [60] => stdClass Object(
        [0] => stdClass Object(
            [id] => 1114
            [price] => 1695
        )
        [1] => stdClass Object
        (
            [id] => 1115
            [price] => 2250
        )
        [2] => stdClass Object
        (
            [id] => 1116
            [price] => 2295
        )
)

Or else can anyone suggest me, how to loop the original array to count the total price for a house ?

  • 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-15T03:19:45+00:00Added an answer on June 15, 2026 at 3:19 am

    You can use array_reduce

    $data = array_reduce($data, function ($a, $b) {
        $id = $b->houseid;
        unset($b->houseid);
        $a[$id][] = $b;
        return $a;
    });
    
    var_dump($data);
    

    Output

    array (size=2)
      58 => 
        array (size=2)
          0 => 
            object(stdClass)[1]
              public 'id' => int 1111
              public 'price' => int 2995
          1 => 
            object(stdClass)[2]
              public 'id' => int 1112
              public 'price' => int 4050
      60 => 
        array (size=3)
          0 => 
            object(stdClass)[3]
              public 'id' => int 1114
              public 'price' => int 1695
          1 => 
            object(stdClass)[4]
              public 'id' => int 1115
              public 'price' => int 2250
          2 => 
            object(stdClass)[5]
              public 'id' => int 1116
              public 'price' => int 2295
    

    Full live Demo

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I group same values in a multidimention array? I want this array(
How can ı add row numbers like this: GROUP 1 RowNumber ID Name Age
how can I split this barcode by group separator with Progress? I've tried chr(29)
I have this scenario. I want group on Country and Category. A store can
I have a problem - i can't compile SqlCipher. I'm using this http://groups.google.com/group/sqlcipher/browse_thread/thread/55c6296b56bf4533/c792bbec6df7d4f4?tvc=2#c792bbec6df7d4f4 instructions
How can I extract the groups from this regex from a file object (data.txt)?
In cakephp, I used $rNo array in WHERE clause. $rooms =$this->find('all',array( 'conditions'=>array(NOT=>array('Room.id'=>$rNo)), 'group'=>array('Room.room_type_id'))); Now,
I have an array that looks like this. [{EntryId=>2, Field1=>National Life Group,DateCreated=>2010-07-30 11:00:14, CreatedBy=>tristanoneil},
can any one know the, convert mysql query in to an php array: this
I want DBSession.query(Article).group_by(Article.created.month).all() But this query can't using How do I do this using

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.