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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:06:59+00:00 2026-05-26T00:06:59+00:00

I have the following array : Array ( [0] => Array ( [ID] =>

  • 0

I have the following array :

Array
(
    [0] => Array
        (
            [ID] => 1
            [PARENT] => 0
            [NAME] => Your first category
        )
    [1] => Array
        (
            [ID] => 2
            [PARENT] => 1
            [NAME] => Your first forum
        )
    [2] => Array
        (
            [ID] => 4
            [PARENT] => 1
            [NAME] => Another Forum
        )
    [3] => Array
        (
            [ID] => 5
            [PARENT] => 1
            [NAME] => Good Forum
        )
    [4] => Array
        (
            [ID] => 6
            [PARENT] => 0
            [NAME] => Top Forum
        )
    [5] => Array
        (
            [ID] => 7
            [PARENT] => 6
            [NAME] => Sub Forum #1
        )
    [6] => Array
        (
            [ID] => 9
            [PARENT] => 7
            [NAME] => Sub Forum #1-1
        )
    [7] => Array
        (
            [ID] => 10
            [PARENT] => 7
            [NAME] => Sub Forum #1-2
        )
    [8] => Array
        (
            [ID] => 8
            [PARENT] => 6
            [NAME] => Sub Forum #2
        )
)

OK Here I have the var_export result as requested :

array (
  0 => 
  array (
    'ID' => '1',
    'PARENT' => '0',
    'NAME' => 'Your first category',
  ),
  1 => 
  array (
    'ID' => '2',
    'PARENT' => '1',
    'NAME' => 'Your first forum',
  ),
  2 => 
  array (
    'ID' => '4',
    'PARENT' => '1',
    'NAME' => 'Another Forum',
  ),
  3 => 
  array (
    'ID' => '5',
    'PARENT' => '1',
    'NAME' => 'Good Forum',
  ),
  4 => 
  array (
    'ID' => '6',
    'PARENT' => '0',
    'NAME' => 'Top Forum',
  ),
  5 => 
  array (
    'ID' => '7',
    'PARENT' => '6',
    'NAME' => 'Sub Forum #1',
  ),
  6 => 
  array (
    'ID' => '9',
    'PARENT' => '7',
    'NAME' => 'Sub Forum #1-1',
  ),
  7 => 
  array (
    'ID' => '10',
    'PARENT' => '7',
    'NAME' => 'Sub Forum #1-2',
  ),
  8 => 
  array (
    'ID' => '8',
    'PARENT' => '6',
    'NAME' => 'Sub Forum #2',
  ),
)

Some of that arrays PARENT value corespond to another array ID value. That helps me to make them nested. But the question is: how can I create an HTML list that will look like that:

<ul>
    <li id="1">
        Your First Category
        <ul>
            <li id="2">
                Your First Forum
            </li>
            <li id="4">
                Another Forum
            </li>
            <li id="5">
                Good Forum
            </li>
        <ul>
    </li>
    <li id="6">
        Top Forum
        <ul>
            <li id="7">
                Sub Forum #1
                <ul>
                    <li id="9">
                        Sub Forum #1-1
                    </li>
                    <li id="10">
                        Sub Forum #1-2
                    </li>
                </ul>
            </li>
            <li id="7">
                Sub Forum #2
            </li>
        <ul>
    </li>
</ul>

Any idea please?

  • 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-26T00:07:00+00:00Added an answer on May 26, 2026 at 12:07 am
    $new_arr = array();
    foreach($arr as $data) $new_arr[$data['id']] = $data;
    
    foreach($new_arr as $id => &$data) $data['parent'] =& $new_arr[$data['parent']];
    

    Now you have a proper array structure.

    But you may have to turn it inside out, since it’s structured by child. But your output is by parent.

    So instead of the second foreach I posted, do this:

    foreach($new_arr as $id => $data) $new_arr[$data['parent']]['children'][] =& $data;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following structure for check-boxes <input type=checkbox name=reg_field['first_name'] value=1 /> First Name<br />
I have written a KornShell (ksh) script that sets an array the following way:
I have a column array with the following values in my sheet: 11, 15,
I have an associative array (object) of the following construction var menu = new
I have the following array in NumPy: A = array([1, 2, 3]) How can
I have the following array, it is currently created sorted by entity_count (outputted by
I have the following array structure in MySQL. There could be no items or
Lets say I have the following array: Array ( [1284487200] => Array ( [title]
Have an issue with the following array... I can't navigate it using $arrayname[0]... it
I have the following sub/criteria: var sq = DetachedCriteria.For<Title>() .CreateAlias(Genres, genre) .Add(Restrictions.IsNull(genre.ParentId)) .SetProjection(Projections.Property<Genre>(g=>g.Name)); var

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.