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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:59:34+00:00 2026-06-18T09:59:34+00:00

I have an array looking like this: Array( [‘some_first_category’] => Array( [‘some_first_name’] => Array(

  • 0

I have an array looking like this:

Array(
   ['some_first_category'] => Array(
            ['some_first_name'] => Array(
                           [0]=>'first@email.com',
                           [1]=>'second@email.com',
                           [2]=>'third@email.com',
                           [3]=>'fourth@email.com' )
             ['some_second_name'] => Array (
                           [1]=>'first@email.com',
                           [2]=>'second@email.com')
             ['some_third_name'] => Array(
                           [1]=>'first@email.com',
                           [2]=>'second@email.com',
                           [3]=>'third@email.com',
                           [4]=>'fourth@email.com' )
   ['some_second_category'] => Array(
            ['some_first_name'] => Array(
                           [0]=>'first@email.com' )
             ['some_second_name'] => Array(
                           [1]=>'first@email.com',
                           [2]=>'second@email.com',
                           [3]=>'third@email.com',
                           [4]=>'fourth@email.com')
             ['some_third_name'] => Array(
                           [1]=>'first@email.com',
                           [2]=>'second@email.com'))

And I want to sort the array by the number of values of that has the names, In my case I want to become this array:

Array(
   ['some_first_category'] => Array(
             ['some_third_name'] => Array(
                           [1]=>'first@email.com',
                           [2]=>'second@email.com',
                           [3]=>'third@email.com',
                           [4]=>'fourth@email.com' )
            ['some_first_name'] => Array(
                           [0]=>'first@email.com',
                           [1]=>'second@email.com',
                           [2]=>'third@email.com',
                           [3]=>'fourth@email.com' )
             ['some_second_name'] => Array (
                           [1]=>'first@email.com',
                           [2]=>'second@email.com')

   ['some_second_category'] => Array(
             ['some_second_name'] => Array(
                           [1]=>'first@email.com',
                           [2]=>'second@email.com',
                           [3]=>'third@email.com',
                           [4]=>'fourth@email.com')
             ['some_third_name'] => Array(
                           [1]=>'first@email.com',
                           [2]=>'second@email.com')
            ['some_first_name'] => Array(
                           [0]=>'first@email.com' ))

This means sorting categories by name by the number(count) of values of the names. Someone can help me?
Thanks in advance,

Aäron

  • 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-18T09:59:35+00:00Added an answer on June 18, 2026 at 9:59 am

    All you need is uasort

    uasort($list, function ($a, $b) {
        $a = count($a);
        $b = count($b);
        return ($a == $b) ? 0 : (($a < $b) ? -1 : 1);
    });
    

    Full Example

    $list = Array(
       'some_first_category' => Array(
                'some_first_name' => Array(
                               0=>'first@email.com',
                               1=>'second@email.com',
                               2=>'third@email.com',
                               3=>'fourth@email.com' ),
                 'some_second_name' => Array (
                               1=>'first@email.com',
                               2=>'second@email.com'),
                 'some_third_name' => Array(
                               1=>'first@email.com',
                               2=>'second@email.com',
                               3=>'third@email.com',
                               4=>'fourth@email.com' )
            ),
       'some_second_category' => Array(
                'some_first_name' => Array(
                               0=>'first@email.com' ),
                 'some_second_name' => Array(
                               1=>'first@email.com',
                               2=>'second@email.com',
                               3=>'third@email.com',
                               4=>'fourth@email.com'),
                 'some_third_name' => Array(
                               1=>'first@email.com',
                               2=>'second@email.com'))
    
        );
    
    $list = array_map(function ($v) {
        uasort($v, function ($a, $b) {
            $a = count($a);
            $b = count($b);
            return ($a == $b) ? 0 : (($a < $b) ? 1 : - 1);
        });
        return $v;
    }, $list);
    
    
    print_r($list);
    

    Output

    Array
    (
        [some_first_category] => Array
            (
                [some_first_name] => Array
                    (
                        [0] => first@email.com
                        [1] => second@email.com
                        [2] => third@email.com
                        [3] => fourth@email.com
                    )
    
                [some_third_name] => Array
                    (
                        [1] => first@email.com
                        [2] => second@email.com
                        [3] => third@email.com
                        [4] => fourth@email.com
                    )
    
                [some_second_name] => Array
                    (
                        [1] => first@email.com
                        [2] => second@email.com
                    )
    
            )
    
        [some_second_category] => Array
            (
                [some_second_name] => Array
                    (
                        [1] => first@email.com
                        [2] => second@email.com
                        [3] => third@email.com
                        [4] => fourth@email.com
                    )
    
                [some_third_name] => Array
                    (
                        [1] => first@email.com
                        [2] => second@email.com
                    )
    
                [some_first_name] => Array
                    (
                        [0] => first@email.com
                    )
    
            )
    
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have and associated array looking like this: array(225) { [0]=> array(3) { [id]=>
I have a map array with objects stuffed with variables looking like this: var
I have an array $arr looking like this: array(3) { [0]=> array(2) { [food]=>
I have an array filled with paths looking like this: library/main/single/list.php library/article/grid/thumbs.php library/footer/tiny.php These
I have an array named 'names' with strings looking like this: [name_23_something, name_25_something, name_2_something];
I have an array of values in PHP looking something like this: $test =
I have an array of objects looking like this obj.date=23/02/2010, obj.regType=0, obj.value=1000; obj.date=23/03/2010, obj.regType=0,
I have an PHP array looking like this: $array['my_data']['value'] = 'some value'; $array['my_own_data']['value'] =
I have a result array that comes back from CodeIgniter looking like this: Array
i have a session looking like this: array(1) { [31]=> array(10) { [aantal]=> int(1)

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.