PHP function that creates a nested ul li?

前端 未结 5 692
隐瞒了意图╮
隐瞒了意图╮ 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:44

    A simple function is all you need.

    function unorderedList($val)
    {
        if (is_array($val)) {
            return '
    • ' . implode('
    • ', array_map('unorderedList', $val)) . '
    '; } else { return $val; } }

    Test code:

    $menu = array('Projects (Menu Level 1)',
                  array('Project 1 (Menu Level 2)',
                        'Project 2 (Menu Level 2)',
                        'Project 3 (Menu Level 2)'),
                  'News (Menu Level 1)',
                  'Contact (Menu Level 1)');
    
    
    echo unorderedList($menu);
    

提交回复
热议问题