Echo a multidimensional array in PHP

后端 未结 9 1604
名媛妹妹
名媛妹妹 2020-11-27 07:24

I have a multidimensional array and I\'m trying to find out how to simply \"echo\" the elements of the array. The depth of the array is not known, so it could be deeply nest

9条回答
  •  没有蜡笔的小新
    2020-11-27 08:10

    There are multiple ways to do that

    1) - print_r($array); or if you want nicely formatted array then

    echo '
    '; print_r($array); echo '
    ';
    

    //-------------------------------------------------

    2) - use var_dump($array) to get more information of the content in the array like datatype and length. //-------------------------------------------------

    3) - you can loop the array using php's foreach(); and get the desired output.

    function recursiveFunction($array) {
        foreach ($array as $val) {
                echo $val['comment_content'] . "\n";
                recursiveFunction($vals['child']);
        }
    }
    

提交回复
热议问题