What are the best practices for using loops in PHP to display data in a table without resetting the table structure?

When displaying data in a table using loops in PHP, it is important to structure the table outside of the loop to avoid resetting the table structure with each iteration. This can be achieved by opening the table before the loop and closing it after the loop, while only outputting the table rows inside the loop.

<table>
<?php
$data = array("John Doe", "Jane Smith", "Bob Johnson");

foreach($data as $row){
    echo "<tr><td>$row</td></tr>";
}
?>
</table>