How can arrays be utilized to simplify the code provided for creating a cross-table?

Using arrays can simplify the code provided for creating a cross-table by storing the row and column headers in arrays, which can then be easily iterated over to generate the table structure dynamically. This approach reduces the redundancy in the code and makes it easier to maintain and update the table layout.

<?php
// Define row and column headers as arrays
$rowHeaders = ['Row 1', 'Row 2', 'Row 3'];
$colHeaders = ['Column 1', 'Column 2', 'Column 3'];

// Generate the table structure using arrays
echo '<table border="1">';
echo '<tr><th></th>';
foreach ($colHeaders as $colHeader) {
    echo '<th>' . $colHeader . '</th>';
}
echo '</tr>';

foreach ($rowHeaders as $rowHeader) {
    echo '<tr><th>' . $rowHeader . '</th>';
    foreach ($colHeaders as $colHeader) {
        echo '<td>' . $rowHeader . ' - ' . $colHeader . '</td>';
    }
    echo '</tr>';
}

echo '</table>';
?>