Created
June 29, 2012 08:31
-
-
Save samdark/3016663 to your computer and use it in GitHub Desktop.
Render leveled list as unordered list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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