Skip to content

Instantly share code, notes, and snippets.

@samdark
Created June 29, 2012 08:31
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save samdark/3016663 to your computer and use it in GitHub Desktop.
Save samdark/3016663 to your computer and use it in GitHub Desktop.
Render leveled list as unordered list
<?php
function render_level_list($items)
{
$level=0;
foreach($items as $item)
{
if($item->level==$level) {
echo "</li>\n";
}
else if($item->level>$level) {
echo "<ul>\n";
}
else {
echo "</li>\n";
for($i=$level-$item->level;$i;$i--) {
echo "</ul>\n</li>\n";
}
}
echo "<li>";
htmlspecialchars($item->title,ENT_QUOTES,'utf-8');
$level=$item->level;
}
for($i=$level;$i;$i--) {
echo "</li>\n</ul>\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment