How can one efficiently loop through nested tables in PHP to retrieve and display relevant information?

When dealing with nested tables in PHP, one efficient way to loop through them is by using recursive functions. By recursively iterating through each level of the nested tables, you can retrieve and display the relevant information without needing to know the exact depth of the nesting.

function displayNestedTables($table) {
    foreach ($table as $row) {
        if (is_array($row)) {
            displayNestedTables($row);
        } else {
            echo $row . "<br>";
        }
    }
}

// Example nested table
$nestedTable = array(
    "Row 1",
    array(
        "Row 2.1",
        "Row 2.2",
        array(
            "Row 2.3.1",
            "Row 2.3.2"
        )
    ),
    "Row 3"
);

displayNestedTables($nestedTable);