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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:57:27+00:00 2026-06-11T00:57:27+00:00

I have an array: $types of: Array ( [0] => Array ( [id] =>

  • 0

I have an array: $types of:

Array
(
    [0] => Array
        (
            [id] => 1
            [cat] => Main
            [type] => name0        )

    [1] => Array
        (
            [id] => 2
            [cat] => Main
            [type] => Name1        )

    [2] => Array
        (
            [id] => 3
            [cat] => Main
            [type] => Name2        )

    [3] => Array
        (
            [id] => 4
            [cat] => Main
            [type] => Name3        )

    [4] => Array
        (
            [id] => 5
            [cat] => Secondary
            [type] => Name4        )

    [5] => Array
        (
            [id] => 6
            [cat] => Secondary
            [type] => Name5        )

    [6] => Array
        (
            [id] => 7
            [cat] => Secondary
            [type] => Name6        )

    [7] => Array
        (
            [id] => 8
            [cat] => Other
            [type] => Name7
        )

    [8] => Array
        (
            [id] => 9
            [cat] => Other
            [type] => Name8
        )

    [9] => Array
        (
            [id] => 10
            [cat] => Other
            [type] => Name9
        )

    [10] => Array
        (
            [id] => 11
            [cat] => Other
            [type] => name10
        )

)

And I’d like to re-build it as a multi directional array. But grouped together by cat
so they’d be Main, Secondary, and Other *those do or could change from the database. As more get added over time, so using $types['cat'] would be recommended.

Also I have another one. that has cat1/cat2 I’ll need to do the same thing with but after i get this one working, i’m hoping i can work that one out.

I’ve looked on here, and on google. and here has a few similar examples, but I wasn’t able to get any of them to work right. As far as I can tell, I think the best route would be to use foreach() and then build a new array?

  • 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-11T00:57:28+00:00Added an answer on June 11, 2026 at 12:57 am

    Something like this?

    <?
    $all = array(
        array('id'=>1, 'cat'=>'Main','type'=>'Name0'),
        array('id'=>2, 'cat'=>'Main','type'=>'Name1'),
        array('id'=>3, 'cat'=>'Main','type'=>'Name3'),
        array('id'=>4, 'cat'=>'Sec','type'=>'Name4'),
        array('id'=>5, 'cat'=>'Sec','type'=>'Name5'),
        array('id'=>6, 'cat'=>'Sec','type'=>'Name6'),
    );
    
    $result = array();
    foreach($all as $array){
        $result[$array['cat']][] = array('id'=>$array['id'],'type'=>$array['type']);
    }
    
    die(print_r($result));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have: $all = array( array('id'=>1, 'cat'=>'Main','type'=>'Name0'), array('id'=>2, 'cat'=>'Main','type'=>'Name1'), array('id'=>3, 'cat'=>'Main','type'=>'Name3'), array('id'=>4, 'cat'=>'Main','type'=>'Name4'), array('id'=>5,
I have an array of items like: var items = [id: animal, type: cat,
I have this form input: echo $this->Form->input('category_id',array('label'=>'Cat&eacute;gorie','type'=>select,'options'=>$categories,'empty'=>false)); Now, $category is filled with those informations:
I have an array of uint-types in C#, After checking if the program is
I have an object whose value may be one of several array types like
I have an array where I fill in the types as string of each
If I have a variant array which holds nothing but simple types, and possible
Here's an example of what I mean: I have an array: array('type'=>'text', 'class'=>'input', 'name'=>'username',
I have an array of type Double() (1 x n ) that I am
I have an array of the type: array(4) {[0]=> string(1) 1 [1]=> string(1) 2

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.