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

  • Home
  • SEARCH
  • 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 7806583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:34:58+00:00 2026-06-02T02:34:58+00:00

i have an array structure like [members] => Members List | 26 [member.php?id=3] =>

  • 0

i have an array structure like

[members] => Members List | 26
[member.php?id=3] => John | 26-26 
[member.php?id=4] => Alice | 26-26 
[member.php?id=5] => Michel | 26-26 
[news] => News details | 45
[alerts] > Alerts | 32

i traverse this using foreach loop. i want to print the Whole list as UL LI. The Members List will be an LI but when its childs comes (memeber.php?id=*) etc then it should inherit UL LI. I want the child to be in a nested LIs

CODE

$counter = 0;
foreach($array as $key => $values)
{
     if($counter == 0)
        {
            echo "<ul>";
        }
    if($key != "" && $key != "END")
        {
            echo "<li>".$values."</li>";
        }
    if($key == "END")
        {
            echo "</ul>";
        }
    $counter++;    
}
  • 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-02T02:35:00+00:00Added an answer on June 2, 2026 at 2:35 am

    I don’t know exactly the problem you have. But i think, you want something like this:

    <ul>
        <li>
            <a href="members">Members List</a>
            <ul>
                <li><a href="member.php?id=3">John</a></li>
                <li><a href="member.php?id=4">Alice</a></li>
                <li><a href="member.php?id=5">Michel</a></li>
            </ul>
        </li>
        <li><a href="news">News details</a></li>
        <li><a href="alerts">Alerts</a></li>
    </ul>
    

    If yes, then i suggest you to change your array structure. Array can also be nested. And it will be easier if you have something like this:

    $data = array(
        array('members', 'Members List', array(
            array('member.php?id=3', 'John'),
            array('member.php?id=4', 'Alice'),
            array('member.php?id=5', 'Michel'),
        )),
        array('news', 'News details'),
        array('alerts', 'Alerts')
    );
    
    • $data is array.
    • Items in $data is array with at least 2 items. 1st item is href/url,
      2nd item is label/text. If it has 3rd item, then it will be the
      children (subitems).
    • Subitems is composed similar to items, where 1st item is href/url, 2nd
      item is label/text.

    Then, the following code will convert it to HTML:

    echo '<ul>';
    foreach ($data as $item) {
        // $item[0] -> href/url, $item[1] -> label/text, $item[2] -> subitems
        echo '<li>';
        echo '<a href="' . $item[0] . '">' . $item[1] . '</a>';
    
        if (isset($item[2])) { // if this item has subitems...
            echo '<ul>';
            foreach ($item[2] as $subitem) {
                // $subitem[0] -> href/url, $subitem[1] -> label/text
                echo '<li><a href="' . $subitem[0] . '">' . $subitem[1] . '</a></li>';
            }
            echo '</ul>';
        }
    
        echo '</li>';
    }
    echo '</ul>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array structure that looks like this: Array ( [0] => Array
Lets say I have an array with a structure like this: $arr= Array( array(
i would like create a array of structure which have a dynamic array :
Does VBA have dictionary structure? Like key<>value array?
I have an array that is a member of a structure: $self->{myArray} = [value1,
I have the folloring array structure: $list = array(); $element1 = array('start' => '10',
I have this ordered List structure that has a structure that has two members,
I have an array structure like this : Array ( [donate] => Array (
I have an array of structures, sorted on a member of a structure, something
I have an array structure like below array { [0]=> { [name] = maulik;

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.