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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:34:13+00:00 2026-05-15T09:34:13+00:00

I am working on a front-end web app where a nested unordered list would

  • 0

I am working on a front-end web app where a nested unordered list would be used for the jQuery plugin mcdropdown.

Here is the data structure from PHP: a nested array of arrays :

Array
(
    [0] => Array
        (
            [fullpath] => ../foil/alphanumeric/
            [depth] => 0
        )

    [1] => Array
        (
            [fullpath] => ../foil/alphanumeric/letters/
            [depth] => 1
        )

    [2] => Array
        (
            [fullpath] => ../foil/alphanumeric/numbers/
            [depth] => 1
        )

    [3] => Array
        (
            [fullpath] => ../foil/alphanumeric/numbers/symbols/
            [depth] => 2
        )
)

Basically, I took the excellent answer from this question on SO, modified it a bit :

global $fullpaths; // $fullpaths contains the above data structure in print_r
$result = '';
$currentDepth = -1;

while(!empty($fullpaths))
{
    $currentNode = array_shift($fullpaths);

    if($currentNode['depth'] > $currentDepth)
    {
        $result .='<ul>';
    }

    if($currentNode['depth'] < $currentDepth)
    {
        $result .=str_repeat('</ul>', $currentDepth - $currentNode['depth']);
    }

    $result .= '<li>'. $currentNode['fullpath'] .'</li>';

    $currentDepth = $currentNode['depth'];

    if(empty($fullpaths))
    {
        $result .= str_repeat('</ul>', 1 + $currentDepth);
    }
}

print $result;

and got the following output:

<ul>
    <li>../foil/alphanumeric/</li>
    <ul>
        <li>../foil/alphanumeric/letters/</li>
        <li>../foil/alphanumeric/numbers/</li>
        <ul>
            <li>../foil/alphanumeric/numbers/symbols/</li>
        </ul>
    </ul>
</ul>

Which cannot be accepted by the mcdropdown jQuery plugin, it expects something like this:

<li rel="1">
'Alphanumeric'
    <ul>
        <li rel="2">'Letters'</li>
        <li rel="3">'Numbers'
            <ul>
                <li rel="4">'Symbols'</li>
            </ul>
        </li>
    </ul>
</li>

To be frank, I don’t quite understand how the answer from that question works, I have been trying to modify that solution to cope with my situation, but still failed.

Any help and suggestion is much appropriated in advance.

  • 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-15T09:34:14+00:00Added an answer on May 15, 2026 at 9:34 am

    If you already have the correct depth values, then you don’t need recursion. I have a similar function that I use for <ul>-<li>-generation:

    function ulli($newlevel, &$level, $UL="ul", $once=1) {
    
      if ($level == $newlevel) {
         echo "</li>\n";
      }
    
      while ($level<$newlevel) {
         $level++;
         echo "\n  <$UL>\n";
      }
    
      while ($level>$newlevel) {
         if ($once-->0) { echo "</li>\n"; } 
         $level--;
         echo "  </$UL>"
         . ($level>0 ? "</li>" : "") . "\n";  // skip for final </ul> (level=0)
      }
    }
    

    It needs a current $level variable for reference (=$currentDepth). And you pass it your depth as $newlevel. It however needs the first depth to be 1.

    Basic usage is like:

    $currentDepth=0;
    foreach ($array as $_) {
       ulli($_["depth"]+1, $currentDepth);
       echo "<li>$_[path]";
    }
    ulli(0, $currentDepth);
    

    Well, quirky. But it worked for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 468k
  • Answers 468k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could use the /compact command line argument for msaccess.exe… May 16, 2026 at 2:16 am
  • Editorial Team
    Editorial Team added an answer Here is the answer from Glassfish Wiki: idle-timeout-in-seconds maximum time… May 16, 2026 at 2:16 am
  • Editorial Team
    Editorial Team added an answer IronRuby types have a few problems with WPF binding... let's… May 16, 2026 at 2:16 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.