Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dmitrymomot/5636219 to your computer and use it in GitHub Desktop.
Save dmitrymomot/5636219 to your computer and use it in GitHub Desktop.
<?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