Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // creating ul-li-ul nested menu using only depth level of next element
- $lists = array(1,1,2,2,2,1,1,2,3,3,2,1);
- $res = "";
- $prev = 0;
- foreach ($lists as $list) {
- if ($list>$prev) $res .= "<ul>\n";
- else $res .= "</li>\n";
- if ($list<$prev) $res .= "</ul></li>\n";
- $res .= '<li>'.$list;
- $prev = $list;
- }
- $res .= "</li></ul>\n";
- echo $res;
Advertisement
Add Comment
Please, Sign In to add comment