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 8084225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:43:24+00:00 2026-06-05T17:43:24+00:00

Yes, I have searched and tried many techniques, but nothing seems to work. Here

  • 0

Yes, I have searched and tried many techniques, but nothing seems to work. Here is my array:

Array
(
    [0] => stdClass Object
        (
            [id] => 119
            [name] => Business3
            [start_date] => 1338789600
            [end_date] => 1354604400
        )

    [1] => stdClass Object
        (
            [id] => 153
            [name] => Business1
            [start_date] => 1338962400
            [end_date] => 1370498400
        )

    [2] => stdClass Object
        (
            [id] => 135
            [name] => Business2  
            [start_date] => 1339653600
            [end_date] => 1356937200
        )
)

I basically want to sort this by the name key, but every function I’ve tried on Stackoverflow doesn’t seem to work, as in, I get a blank page with no error.

I tried this:

function array_sort_by_column(&$arr, $col, $dir = SORT_ASC) {
    $sort_col = array();
    foreach ($arr as $key=> $row) {
        $sort_col[$key] = $row[$col];
    }

    array_multisort($sort_col, $dir, $arr);
}

array_sort_by_column(json_decode(json_encode($businesses), true), 'name');

But that didn’t work.

Any ideas?

  • 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-05T17:43:26+00:00Added an answer on June 5, 2026 at 5:43 pm

    You’re almost right, but $row[$col] tries to access the objects like an array. You want something like $row->{$col} instead. Here’s a simpler, working example:

    $db = array(
      0 => (object) array('name' => 'Business3'),
      1 => (object) array('name' => 'Business2'),
      2 => (object) array('name' => 'Business1')
    );
    
    $col  = 'name';
    $sort = array();
    foreach ($db as $i => $obj) {
      $sort[$i] = $obj->{$col};
    }
    
    $sorted_db = array_multisort($sort, SORT_ASC, $db);
    
    print_r($db);
    

    Outputs:

    Array
    (
        [0] => stdClass Object
            (
                [name] => Business1
            )
    
        [1] => stdClass Object
            (
                [name] => Business2
            )
    
        [2] => stdClass Object
            (
                [name] => Business3
            )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched this on the internet, but have found no solution... Here is
I searched over .... I see many advantages, but it seems that all the
I have searched this web looking for an answer, but it seems that this
I have completed the assignment (yes it is for a programming class), but I
I have the following code (Yes I know it's quite long winded, but I
I have searched, but frustratingly have been unable to figure out why I am
I have searched for and found various q/a on this error, but have not
I have searched around but have yet to find a satisfying answer for my
Firstly, I have searched for related answers, there is a few - but couldn't
Very basic, and very annoying, I have searched solution for many hours with no

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.