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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:23:50+00:00 2026-05-25T14:23:50+00:00

Hi thinking i have an array like this : [0]=>[ [0]=>’Hey’, [1]=>’H’, [2]=>’He’, ]

  • 0

Hi thinking i have an array like this :

[0]=>[
   [0]=>'Hey',
   [1]=>'H',
   [2]=>'He',



]

now i would like to sort by number chars and return somenthing like this:

[0]=>[
   [0]=>'H',
   [1]=>'He',
   [2]=>'Hey',
]

maybe the answer is array_sort() but i’m not able to do that. also i would not like to loop the array to check the number chars of values, but if it’s the only way i need to use anyway 😛

BTW

how to return this same array ordered by [‘name’] key number of chars ASC (h – he -hey -heyh – heyhey )?

array(5) {
  [0]=>
  array(2) {
    ["id"]=>
    object(MongoId)#26 (1) {
      ["$id"]=>
      string(24) "4e72858ccaa47ca608030000"
    }
    ["name"]=>
    string(4) "h"
  }
  [1]=>
  array(2) {
    ["id"]=>
    object(MongoId)#29 (1) {
      ["$id"]=>
      string(24) "4e72858ccaa47ca608040000"
    }
    ["name"]=>
    string(10) "hey"
  }
  [2]=>
  array(2) {
    ["id"]=>
    object(MongoId)#31 (1) {
      ["$id"]=>
      string(24) "4e72858ccaa47ca608400000"
    }
    ["name"]=>
    string(1) "heyhey"
  }
  [3]=>
  array(2) {
    ["id"]=>
    object(MongoId)#33 (1) {
      ["$id"]=>
      string(24) "4e72858ccaa47ca6081a0000"
    }
    ["name"]=>
    string(6) "he"
  }
  [4]=>
  array(2) {
    ["id"]=>
    object(MongoId)#35 (1) {
      ["$id"]=>
      string(24) "4e72858ccaa47ca6083d0000"
    }
    ["name"]=>
    string(3) "heyh"
  }
}
  • 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-25T14:23:51+00:00Added an answer on May 25, 2026 at 2:23 pm

    If you want to sort by the number of characters, usort is the way to go. It lets you define your own sorting function.

    function lengthsort($s1, $s2) {
        if (strlen($s1['name']) < strlen($s2['name'])) {
            return -1;
        } elseif (strlen($s1['name']) > strlen($s2['name'])) {
            return 1;
        } else {
            return 0;
        }
    }
    usort($array, 'lengthsort');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array named 'names' with strings looking like this: [name_23_something, name_25_something, name_2_something];
let's say I have a matrix (array) like this example, but much larger: 0
I have an array that looks like this: Array ( [0] => Array (
I have a multi-dim string array something like this:- string[,] names = new string[2,
I have been thinking of maybe writing a little tool that logs into SO
This question about Timers for windows services got me thinking: Say I have (and
I have created an element like this: var myDiv = new Element('div'); myDiv.update('Hello!'); I
i've been thinking if something like this is possible. // this creates a variable
I have to have a result which looks like this: ({1: 'string', 2: 'anotherstring',
i was wondering if this setup would work. i have to crank out a

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.