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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:56:50+00:00 2026-05-25T20:56:50+00:00

anyone can help me with some coding here? I got the following array config:

  • 0

anyone can help me with some coding here?

I got the following array config:

$array[1]['areaname'] = 'Area 1';
$array[1][1]['areaname'] = 'Sub Area 1';
$array[1][2]['areaname'] = 'Sub Area 2';
$array[1][3]['areaname'] = 'Sub Area 3';
$array[2]['areaname'] = 'Area 2';
$array[2][1]['areaname'] = 'Sub Area 1';

I want display the following:

<ul>
    <li>
        Area 1
        <ul>
            <li>Sub Area 1</li>
            <li>Sub Area 2</li>
            <li>Sub Area 3</li>
        </ul>
    </li>
    <li>
        Area 2
        <ul>
            <li>Sub Area 1</li>
        </ul>
    </li>
</ul>

I need a code where I can have as many sub area as I want. Example:

$array[1][1][2][3][4]['areaname'];

There are also another condition. The array got other elements such as $array[1][‘config’], $array[1][2][3][‘link’] or $array[1][another array of elements that should not be into the loop] … I only need print the areaname.

  • 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-25T20:56:50+00:00Added an answer on May 25, 2026 at 8:56 pm
    $array = array();
    $array[1]['areaname'] = 'Area 1';
    $array[1][1]['areaname'] = 'Sub Area 1';
    $array[1][2]['areaname'] = 'Sub Area 2';
    $array[1][3]['areaname'] = 'Sub Area 3';
    $array[2]['areaname'] = 'Area 2';
    $array[2][1]['areaname'] = 'Sub Area 1';
    
    function generate_html_list_recursive( &$data, $labelKey )
    {
        // begin with an empty html string
        $html = '';
    
        // loop through all items in this level
        foreach( $data as $key => &$value )
        {
            // where only interested in numeric items
            // as those are the actual children
            if( !is_numeric( $key ) )
            {
                // otherwise continue
                continue;
            }
    
            // if no <li> has been created yet, open the <ul>
            $html .= empty( $html ) ? '<ul>' : '';
    
            // extract the label from this level's array, designated by $labelKey
            $label = isset( $value[ $labelKey ] ) ? $value[ $labelKey ] : '';
    
            // open an <li> and append the label
            $html .= '<li>' . $label;
    
            // call this funcion recursively
            // with the next level ($value) and label key ($labelKey)
            // it will figure out again whether that level has numeric children as well
            // returns a new complete <ul>, if applicable, otherwise an empty string
            $html .= generate_html_list_recursive( $value, $labelKey );
    
            // close our currently open <li>
            $html .= '</li>';
        }
    
        // if this level has <li>'s, and therefor an opening <ul>, close the <ul>
        $html .= !empty( $html ) ? '</ul>' : '';
    
        // return the resulting html
        return $html;
    }
    
    echo generate_html_list_recursive( $array, 'areaname' );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone help? I have some code that is shared between 2 projects. The
Are there some help resources, or can anyone give me a brief Idea how
Can anyone suggest some good browser add-on tools/extensions to help with development? I have
I am new in Symbian UIQ. So anyone can help me out about following
I hope someone can help!!! In coding a form validation, I got the error
I was wondering if anyone can help me get started with creating a room
Wondering if anyone can help me with this annoying but trivial (in terms of
Wonder if anyone can help me understand how to sum up the column of
I wonder if anyone can help improve my understanding of JOINs in SQL. [If
I wonder if anyone can help - I have this error showing recently when

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.