How can arrays be utilized for creating tables in PHP output instead of manually writing them?

To create tables in PHP output using arrays instead of manually writing them, you can define the table structure as an array with nested arrays representing rows and columns. Then, iterate over the arrays to generate the table HTML dynamically. This approach helps in maintaining and updating the table structure more efficiently.

<?php
// Define the table data as an array
$tableData = array(
    array('Name', 'Age', 'Country'),
    array('John', 25, 'USA'),
    array('Alice', 30, 'Canada'),
    array('Bob', 22, 'UK')
);

// Generate the table HTML dynamically
echo '<table border="1">';
foreach ($tableData as $row) {
    echo '<tr>';
    foreach ($row as $cell) {
        echo '<td>' . $cell . '</td>';
    }
    echo '</tr>';
}
echo '</table>';
?>