What are best practices for generating HTML tables from multi-dimensional arrays in PHP?

When generating HTML tables from multi-dimensional arrays in PHP, it is important to iterate through the array and properly structure the table with the array data. One common approach is to use nested loops to iterate through the rows and columns of the array, creating table rows and cells accordingly.

<?php
// Sample multi-dimensional array
$data = [
    ['Name', 'Age', 'Country'],
    ['John', 25, 'USA'],
    ['Alice', 30, 'Canada'],
    ['Bob', 22, 'UK']
];

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