What potential issues can arise when using nested loops in PHP to create tables with multiple elements in each row?
One potential issue when using nested loops in PHP to create tables with multiple elements in each row is that it can lead to inefficient code and make the logic harder to follow. To solve this, you can use a single loop to iterate through the data and calculate the appropriate index for each element in the table.
<?php
$data = [
['John', 'Doe', 'john.doe@example.com'],
['Jane', 'Smith', 'jane.smith@example.com'],
['Tom', 'Brown', 'tom.brown@example.com']
];
echo '<table>';
foreach ($data as $row) {
echo '<tr>';
foreach ($row as $cell) {
echo '<td>' . $cell . '</td>';
}
echo '</tr>';
}
echo '</table>';
?>