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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:26:10+00:00 2026-05-25T02:26:10+00:00

Ok, I have an array like so: $my_array = array( ‘hi’ => array(‘description’ =>

  • 0

Ok, I have an array like so:

$my_array = array(
    'hi' => array('description' => 'how are you?', 'title' => 'Hello', 'link' => 'http://mylink.com'),
    'bye' => array('description' => array('Goodbye!', 'see ya'), 'title' => 'See Ya Later', 'link' => 'http://mybyelink.com'),
    'not_now' => array('description' => array('I am away now!', 'gone'), 'title' => 'Away', 'link' => 'http://myawaylink.com'),
    'back' => array('description' => array('I am back now!', 'back', 'present'), 'title' => 'Here', 'link' => 'http://mybacklink.com'),
);

So I would like the array to be ordered, within php code, somehow so that it orders it by the TITLE of each array bound: $my_array['hi']['title'], $my_array['bye']['title'], $my_array['not_now']['title'], and $my_array['back']['title'], but it MUST keep the array intact so that all of the values within the hi, bye, not_now, and back are the exact same and all of the arrays (if any are in it, are also the same).

So this array will need to be ordered in ABC order depending on the title, so should return in this order:

$my_array = array(
    'not_now' => array('description' => array('I am away now!', 'gone'), 'title' => 'Away', 'link' => 'http://myawaylink.com'),
    'hi' => array('description' => 'how are you?', 'title' => 'Hello', 'link' => 'http://mylink.com'),
    'back' => array('description' => array('I am back now!', 'back', 'present'), 'title' => 'Here', 'link' => 'http://mybacklink.com'),
    'bye' => array('description' => array('Goodbye!', 'see ya'), 'title' => 'See Ya Later', 'link' => 'http://mybyelink.com'),
);

Titles are in ABC order here: Away, Hello, Here, and See Ya Later.

How can I do this and still keep the array intact with all of the sub-arrays in it also?

Thanks guys 🙂

  • 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-25T02:26:11+00:00Added an answer on May 25, 2026 at 2:26 am

    You want to use the uasort function with a user-defined sort function using strnatcmp in the function. Here is an example for your code:

    function titleSort($a, $b) {
        return strnatcmp($a['title'], $b['title']);
    }
    
    uasort($my_array, 'titleSort');
    

    If desired you could add some sanity checking on the input variables to make sure they are arrays by using is_array.

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

Sidebar

Related Questions

I'm creating my own JavaScript Array-like object and I have methods that call closures.
Lets say I have an array like this: string [] Filelist = ... I
When you have an array like this: int foo[3][2][2]; and you make: int *bar
I have a 2D bitmap-like array of let's say 500*500 values. I'm trying to
I have byte array as input. I would like to convert that array to
I have a byte array in memory, read from a file. I would like
I have a 2 dimensional array, like so: char[,] str = new char[2,50]; Now,
I have a one-dimensional array of strings in JavaScript that I'd like to turn
If you have something like: val myStuff = Array(Person(joe,40), Person(mary, 35)) How do you
I have a vector-like class that contains an array of objects of type T

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.