PHP function that creates a nested ul li?

前端 未结 5 712
隐瞒了意图╮
隐瞒了意图╮ 2021-01-07 15:18

I am attemptting to attach a small CMS to a website I am creating. However I have come across a small problem. The CMS uses PHP functions for inserting menus, these PHP func

5条回答
  •  [愿得一人]
    2021-01-07 15:57

    This would be a excellent example of the use of recursion. An array (with sub-arrays within it) defines each level, and a function loops, calling itself whenever it finds a new array to process. As long as the function cleans up appropriately (closing the

  • & ), it's largely automatic.

    ';
        foreach($tree as $item) {
            if (is_array($item)) {
                olLiTree($item);
            } else {
                echo '
  • ', $item, '
  • '; } } echo '
'; } olLiTree($tree); // kick off from the top level

提交回复
热议问题