What are some best practices for dynamically generating tables in PHP with varying array lengths?

When dynamically generating tables in PHP with varying array lengths, it's important to iterate through the array and dynamically create table rows based on the array elements. One approach is to use a foreach loop to iterate through the array and generate table rows for each element. By dynamically generating the table rows, you can accommodate arrays of different lengths without hardcoding the table structure.

<table>
<?php
$array = ['Apple', 'Banana', 'Orange'];

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