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++;
}
I don’t know exactly the problem you have. But i think, you want something like this:
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:
2nd item is label/text. If it has 3rd item, then it will be the
children (subitems).
item is label/text.
Then, the following code will convert it to HTML: