How to create a ul - li menu from a tree like array?

前端 未结 3 1327
醉酒成梦
醉酒成梦 2021-01-06 09:52

I have an array with title and children index.

title is always not-null. children is an array, empty or not-empt

3条回答
  •  一生所求
    2021-01-06 10:23

    I'm sure this will work :

        function menu($arr) {
            echo "
      "; foreach ($arr as $val) { if (!empty($val['children'])) { echo "
    • " . $val['title']; menu($val['children']); echo "
    • "; } else { echo "
    • " . $val['title'] . "
    • "; } } echo "
    "; }

提交回复
热议问题