What are the potential pitfalls when trying to display nested lists from an array in PHP?

When trying to display nested lists from an array in PHP, one potential pitfall is not properly handling the nested structure of the array. To solve this issue, you can use recursion to iterate through the nested arrays and display them as nested lists in HTML.

function displayNestedLists($array) {
    echo '<ul>';
    foreach ($array as $item) {
        echo '<li>';
        if (is_array($item)) {
            displayNestedLists($item);
        } else {
            echo $item;
        }
        echo '</li>';
    }
    echo '</ul>';
}

$array = array(
    'Item 1',
    'Item 2',
    array(
        'Nested Item 1',
        'Nested Item 2'
    ),
    'Item 3'
);

displayNestedLists($array);