How can a pre-formatted table be created in PHP for different content with varying numbers of rows?

When creating a pre-formatted table in PHP for content with varying numbers of rows, you can dynamically generate the table rows based on the content provided. One way to achieve this is by using a loop to iterate through the content and generate the rows accordingly.

<?php
// Sample content with varying numbers of rows
$content = array(
    array('Name', 'Age'),
    array('John', 25),
    array('Alice', 30),
    array('Bob', 22)
);

// Start the table
echo '<table>';

// Loop through the content and generate table rows
foreach($content as $row) {
    echo '<tr>';
    foreach($row as $cell) {
        echo '<td>' . $cell . '</td>';
    }
    echo '</tr>';
}

// End the table
echo '</table>';
?>