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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:00:39+00:00 2026-06-14T23:00:39+00:00

I have this multidimensional assoc $modules array in cakephp 2.2.3: array( ‘type1’ => array(

  • 0

I have this multidimensional assoc $modules array in cakephp 2.2.3:

array(
    'type1' => array(
        (int) 0 => array(
            'name' => 'name16',
            'type' => '1',
            'category' => 'categoryC',
            'zone' => 'zone1'
        ),
        (int) 1 => array(
            'name' => 'name17',
            'type' => '1',
            'category' => 'categoryB',
            'zone' => 'zone1'
        ),
        (int) 2 => array(
            'name' => 'name18',
            'type' => '1',
            'category' => 'categoryA',
            'zone' => 'zone3'
        ),
        (int) 3 => array(
            'name' => 'name19',
            'type' => '1',
            'category' => 'categoryC',
            'zone' => 'zone3'
        ),
        (int) 4 => array(
            'name' => 'name22',
            'type' => '1',
            'category' => 'categoryA',
            'zone' => 'zone2'
        )
    ),
    'type2' => array(
        (int) 0 => array(
            'name' => 'name1',
            'type' => '2',
            'category' => 'categoryB',
            'zone' => 'zone2'
        ),
        (int) 1 => array(
            'name' => 'name2',
            'type' => '2',
            'category' => 'categoryB',
            'zone' => 'zone2'
        ),
        (int) 2 => array(
            'name' => 'name3',
            'type' => '2',
            'category' => 'categoryA',
            'zone' => 'zone1'
        ),
        (int) 3 => array(
            'name' => 'name4',
            'type' => '2',
            'category' => 'categoryC',
            'zone' => 'zone3'
        ),
        (int) 4 => array(
            'name' => 'name5',
            'type' => '2',
            'category' => 'categoryA',
            'zone' => 'zone3'
        )
    )
)

and I want to rearrange it like

array(
    'zone1' => array(
        'type1' => array(
            (int) 0 => array(
                'name' => 'name17',
                'type' => '1',
                'category' => 'categoryB'
            ),
            (int) 1 => array(
                'name' => 'name16',
                'type' => '1',
                'category' => 'categoryC'
            )
        ),
        'type2' => array(
            (int) 0 => array(
                'name' => 'name3',
                'type' => '2',
                'category' => 'categoryA'
            )
        )
    ),
    'zone2' => array(
        'type1' => array(
            (int) 0 => array(
                'name' => 'name22',
                'type' => '1',
                'category' => 'categoryA'
            )
        ),
        'type2' => array(
            (int) 0 => array(
                'name' => 'name1',
                'type' => '2',
                'category' => 'categoryB'
            ),
            (int) 1 => array(
                'name' => 'name2',
                'type' => '2',
                'category' => 'categoryB'
            )
        )
    ),
    'zone3' => array(
        'type1' => array(
            (int) 0 => array(
                'name' => 'name18',
                'type' => '1',
                'category' => 'categoryA'
            ),
            (int) 0 => array(
                'name' => 'name19',
                'type' => '1',
                'category' => 'categoryC'
            )
        ),
        'type2' => array(
            (int) 0 => array(
                'name' => 'name5',
                'type' => '2',
                'category' => 'categoryA'
            ),
            (int) 1 => array(
                'name' => 'name4',
                'type' => '2',
                'category' => 'categoryC'
            )
        )
    )   
)

where ‘category’ should be sorted alphabetically within each parent ‘type’

I tried with

$modules = Hash::combine($modules, '{n}', '{n}.{n}', '{s}.{s}.{n}.zone');

but with no success. I guess I’m not using Hash::combine as I should…
Thanks, Marius

  • 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-14T23:00:40+00:00Added an answer on June 14, 2026 at 11:00 pm

    Just use a foreach inside a foreach to walk through your array and construct a new one based on your preference.

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

Sidebar

Related Questions

I have this multidimensional array: $data[] = array('name' => 'Mini 16', 'id' => 105);
I have an multidimensional array that looks like this: Array ( [0] => Array
I have a multi dimensional array, like this: array('name' => array('title'=>'Title','date'=>'Created')) I store it
I have this multidimensional array: Array ( [0] => Array ( [id] => 1
Possible Duplicate: Convert multidimensional array into single array I have this array: Array (
I have this multidimensional array. I need to search it and return only the
I have this multidimensional array: Array ( [car] => Array ( [responsecode] => 200
I have this multidimensional array: Array ( [0] => Array ( [0] => 2012-02-26
I have a multidimensional array converted to JSON data in this format. [[null,null,null,null,null,null],[null,null,null,1,1,null],[null,null,null,null,1,1],[null,null,null,null,null,null],[null,null,null,null,null,null]] I
I have this example: var name; var id; var array = []; $.each(data, function(index,

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.