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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:19:57+00:00 2026-06-13T21:19:57+00:00

I am trying to sort by a column(s) in the following data structure that

  • 0

I am trying to sort by a column(s) in the following data structure that I have built like this:

 $counter = 1;
 $entity_list = array();

 foreach($result as $rec){
   $entity_list[$counter]['student_first_name'] = $rec->firstname;
   $entity_list[$counter]['student_last_name'] = $rec->lastname;
   $entity_list[$counter]['course_name'] = $rec->fullname;
   .
   .
   $counter++;
 }//end foreach

This is a var_dump of the $entity_list data structure.

array (size=150)     
  1 => 
  array (size=3)
    'student_first_name' => string 'Jane' (length=6)
    'student_last_name' => string 'Smith' (length=7)
    'course_name' => string 'Algebra 1A-MOD' (length=14)

  2 => 
  array (size=3)
    'student_first_name' => string 'Fred' (length=6)
    'student_last_name' => string 'Jones' (length=7)
    'course_name' => string 'Algebra 1A-MOD' (length=14)
   .
   .
   .

How do I use asort() or ksort() on this structure? I think i should be using ksort(), as it works on a key. I have tried ksort($entity_list,’student_last_name’), or asort($entity_list,’current_grade’) for example.

Thank you.

  • 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-13T21:19:58+00:00Added an answer on June 13, 2026 at 9:19 pm

    You can use uasort

    uasort($entity_list, 'mySort');
    
    function mySort($a, $b) {
        return ($a['student_last_name'] <==> $b['student_last_name']);
    }
    

    But if your data come from a DB, it would be a lot easier and lighter to ORDER BY.

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

Sidebar

Related Questions

I am trying to sort a two-dimensional array by a timestamp column Descending. This
I have an NSTableView that I am trying to sort. The data source is
I'm trying to sort a column of data in a GTK tree view non-alphabetically.
Trying to sort this array of objects according to (1) depth and (2) weight,
I have a table like this: | X | Y | Data | ----------------
I am working with a set of data that looks something like the following.
Trying to sort the following TEAM_TOTAL Column Desc MATCHID TEAM_TOTAL ---------- ----------------- 573 Total
I'm using SlickGrid with DataView and I'm trying to set a default sort column
Been trying to sort this one out for a while. I'd really appreciate any
I am trying to sort an array in PHP by date and time which

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.