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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:06:40+00:00 2026-05-24T01:06:40+00:00

I looked around for a solution, both on Google and SO, but it’s pretty

  • 0

I looked around for a solution, both on Google and SO, but it’s pretty late, so apologies if I’m missing something really obvious.

In PHP, I have an array set up, $rooms, such that it looks like:

Array
(
  [0] => Array
  (
    [title] => Bedroom
    [area] => 16.00
    [length] => 4.00
    [width] => 4.00
    [level] => U
  )
  [1] => Array
  (
    [title] => Kitchen
    [area] => 18.00
    [length] => 2.00
    [width] => 9.00
    [level] => 1
  )
  [2] => Array
  (
    [title] => Basement
    [area] => 32.00
    [length] => 8.00
    [width] => 4.00
    [level] => 2
  )
  [3] => Array
  (
    [title] => Bathroom
    [area] => 9.00
    [length] => 3.00
    [width] => 3.00
    [level] => L
  )
  [3] => Array
  (
    [title] => Deck
    [area] => 9.00
    [length] => 3.00
    [width] => 3.00
    [level] => n/a
  )
)

I’m wanting to group the entries with the same level keys (I.e., “sort them so they’re together”). However, I also need the level groups to be in the following order: 1, n/a, 2, 3, 4, (and on), U, L, B

I figure I need to use uasort();, but I just can’t wrap my head around the examples.

Any help? Many thanks!

  • 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-05-24T01:06:41+00:00Added an answer on May 24, 2026 at 1:06 am

    Try with:

    $data      = array();
    $output    = array();
    $levelSort = array('1', 'n/a', '2', '3', '4', '(and on)', 'U', 'L', 'B');
    
    foreach ( $rooms as $room ) {
      if ( empty($data[$room['level']]) ) {
        $data[$room['level']] = array();
      }
    
      $data[$room['level']][] = $room;
    }
    
    foreach ( $levelSort as $level ) {
      $levelData = !empty($data[$level]) ? $data[$level] : array();
      $output    = array_merge($output, $levelData);
    }
    
    var_dump($output);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've looked around for a solution for this but it must be something a
I've already looked around but couldn't find the exact solution/problem I'm having right now.
I have looked around for a solution to this problem, but it's so wonky
I've looked around StackOverflow and with Google and was unable to find a solution
I'm very new to PHP. I have looked around at other questions but none
I looked around on the site but wasn't able to locate a solution to
I looked around and found that there is an onerror function for flexigrid but
I've looked around for a physics engine that will play nicely with Android, but
I've looked around at pretty much all the SMS posts here on SO and
I've looked around on stackoverflow for a similar question, but haven't found exactly what

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.