[Solved] PHP nested array into HTML list


What you are looking for is called Recursion. Below is a recursive function that calls itself if the value of the array key is also an array.

function printArrayList($array)
{
    echo "<ul>";

    foreach($array as $k => $v) {
        if (is_array($v)) {
            echo "<li>" . $k . "</li>";
            printArrayList($v);
            continue;
        }

        echo "<li>" . $v . "</li>";
    }

    echo "</ul>";
}

4

solved PHP nested array into HTML list