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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:14:04+00:00 2026-06-06T20:14:04+00:00

Its generally related to a question in magento ..but i think using core php

  • 0

Its generally related to a question in magento ..but i think using core php can also give me a wat i want

Im having a looping array issue here,My aray is like this

    Array
    (
        [0] => Array
            (
                [category_id] => 2
                [parent_id] => 1
                [name] => Koffersenkisten
                [is_active] => 0
                [position] => 1
                [level] => 1
                [children] => Array
                    (
                        [0] => Array
                            (
                                [category_id] => 40
                                [parent_id] => 2
                                [name] => Muziek
                                [is_active] => 1
                                [position] => 1
                                [level] => 2
                                [children] => Array
                                    (
                                        [0] => Array
                                            (
                                                [category_id] => 46
                                                [parent_id] => 40
                                                [name] => Gitaar koffer
                                                [is_active] => 1
                                                [position] => 1
                                                [level] => 3
                                                [children] => Array
                                                    (
                                                        [0] => Array
                                                            (
                                                                [category_id] => 50
                                                                [parent_id] => 46
                                                                [name] => Bas gitaar koffer
                                                                [is_active] => 1
                                                                [position] => 1
                                                                [level] => 4
                                                                [children] => Array
                                                                    (
                                                                    )

                                                            )

                                                        [1] => Array
                                                            (
                                                                [category_id] => 51
                                                                [parent_id] => 46
                                                                [name] => Electrische gitaar koffer
                                                                [is_active] => 1
                                                                [position] => 2
                                                                [level] => 4
                                                                [children] => Array
                                                                    (
                                                                    )

                                                            )

                                                        [2] => Array
                                                            (
                                                                [category_id] => 47
                                                                [parent_id] => 46
                                                                [name] => Akoestische gitaar koffer
                                                                [is_active] => 1
                                                                [position] => 3
                                                                [level] => 4
                                                                [children] => Array
                                                                    (
                                                                    )

                                                            )

                                                        [3] => Array
                                                            (
                                                                [category_id] => 49
                                                                [parent_id] => 46
                                                                [name] => Gitaar soft cases
                                                                [is_active] => 1
                                                                [position] => 4
                                                                [level] => 4
                                                                [children] => Array
                                                                    (
                                                                    )

                                                            )

                                                        [4] => Array
                                                            (
                                                                [category_id] => 52
                                                                [parent_id] => 46
                                                                [name] => Gitaar gig bags
                                                                [is_active] => 1
                                                                [position] => 5
                                                                [level] => 4
                                                                [children] => Array
                                                                    (
                                                                    )

                                                            )

                                                        [5] => Array
                                                            (
                                                                [category_id] => 53
                                                                [parent_id] => 46
                                                                [name] => Pedalboards
                                                                [is_active] => 1
                                                                [position] => 6
                                                                [level] => 4
                                                                [children] => Array
                                                                    (
                                                                    )

                                                            )

                                                        [6] => Array
                                                            (
                                                                [category_id] => 48
                                                                [parent_id] => 46
                                                                [name] => Amp Utility Vehicles
                                                                [is_active] => 1
                                                                [position] => 7
                                                                [level] => 4
                                                                [children] => Array
                                                                    (
                                                                    )

                                                            )

                                                    )

                                            )

                                        [1] => Array
                                            (
                                                [category_id] => 67
                                                [parent_id] => 40
                                                [name] => Percussie koffer
                                                [is_active] => 1
                                                [position] => 2
                                                [level] => 3
                                                [children] => Array
                                                    (
                                                        [0] => Array
                                                            (
                                                                [category_id] => 73
                                                                [parent_id] => 67
                                                                [name] => Tom koffer
                                                                [is_active] => 1
                                                                [position] => 1
                                                                [level] => 4
                                                                [children] => Array
                                                                    (
                                                                    )

                                                            )

.......


......


>> it goes like this based on the number of categories

How do i get a simple array of the above like this

array('2' => 'Koffersenkisten','40'=> 'Muziek'...........etc); where 2 is the category_id and Koffersenkisten is the name
  • 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-06T20:14:06+00:00Added an answer on June 6, 2026 at 8:14 pm

    This function iterates over all items, and recurses when children are found. It passes the output array along at every invocation and appends to it:

    function get_cats(array &$output, array $arr)
    {
            foreach ($arr as $item) {
                    $output[$item['category_id']] = $item['name'];
                    if (count($item['children'])) {
                            get_cats($output, $item['children']);
                    }
            }
    }
    
    // start with empty result
    $output = array();
    get_cats($output, $a);
    print_r($output);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a cgal related question, but I think it is also a general
This question is closely related to this one but i think is more general.
This is a general question of sorts, but do you think that it's important
This is related to the question 'Why do stacks typically grow downwards?' , but
A similar question was asked here , but the answers generally all seem to
The issue is gaming related, but I think it could be applied to other
It's general question nothing related with code. I want to know that video which
In general, I have the following scenario: Fetch product and its related data from
How ASP.NET compiles its assemblies generally confuses me. It seems that I cannot program
So generally I'm using Netty and it's BigEndianHeapChannelBuffer to receive unsinged short (from c++

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.