Traverse Array and Display In Bullet Points

后端 未结 2 800
北荒
北荒 2021-01-17 06:36

I want to traverse this array and display, \'comment\' as bullet points.

Array
(
    [1] => Array
        (
            [id] => 1
            [comment]         


        
2条回答
  •  抹茶落季
    2021-01-17 07:06

    You need a little bit of recursion

    function traverse_array($array)
    {
        echo '
      '; foreach($array as $element) { echo '
    • '; if(isset($element['comment'])) { echo $element['comment']; } if(is_array($element['children']) && count($element['children']) > 0) { traverse_array($element['children']); } echo '
    • '; } echo '
    '; } traverse_array($the_big_array);

提交回复
热议问题