Wednesday, April 18, 2012

Printing UL LI nested in Foreach Loop

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++;
}




No comments:

Post a Comment