vladkras

ul-li-ul nested menu

Jan 14th, 2014
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.34 KB | None | 0 0
  1. // creating ul-li-ul nested menu using only depth level of next element
  2. $lists = array(1,1,2,2,2,1,1,2,3,3,2,1);
  3. $res = "";
  4. $prev = 0;
  5. foreach ($lists as $list) {
  6.     if ($list>$prev) $res .= "<ul>\n";
  7.     else $res .= "</li>\n";
  8.     if ($list<$prev) $res .= "</ul></li>\n";
  9.     $res .= '<li>'.$list;
  10.     $prev = $list;
  11. }
  12. $res .= "</li></ul>\n";
  13. echo $res;
Advertisement
Add Comment
Please, Sign In to add comment