In what situations would using a loop to fill in missing table cells be necessary when outputting data in PHP?

When outputting data in a table format in PHP, there may be situations where certain cells are missing data. In such cases, using a loop to fill in the missing table cells with placeholders or empty values can help maintain the structure and readability of the table.

// Sample array with missing data
$data = [
    ['John', 'Doe', 'john.doe@example.com'],
    ['Jane', '', 'jane@example.com'],
    ['Alice', 'Smith', ''],
];

// Output table with missing cell handling
echo '<table>';
foreach ($data as $row) {
    echo '<tr>';
    foreach ($row as $cell) {
        echo '<td>' . ($cell != '' ? $cell : 'N/A') . '</td>';
    }
    echo '</tr>';
}
echo '</table>';