How can PHP code be used to dynamically generate HTML content within a loop to create a series of tables?

To dynamically generate HTML content within a loop to create a series of tables, you can use PHP to loop through your data and generate the table rows and columns dynamically. Within the loop, you can concatenate the HTML code for each table row and column. This allows you to create multiple tables or rows based on the data you have.

<?php
// Sample data
$data = array(
    array("Name", "Age", "City"),
    array("John", 25, "New York"),
    array("Alice", 30, "Los Angeles"),
    array("Bob", 22, "Chicago")
);

// Generate tables
foreach ($data as $row) {
    echo "<table border='1'>";
    echo "<tr>";
    foreach ($row as $cell) {
        echo "<td>$cell</td>";
    }
    echo "</tr>";
    echo "</table>";
}
?>