What is the purpose of using a for loop in PHP to generate a table output?

When generating a table output in PHP, using a for loop can help automate the process of creating rows and columns based on a set of data. This can be especially useful when dealing with arrays or databases where you need to display multiple rows of data in a structured format. By using a for loop, you can iterate through the data and dynamically generate the table rows without having to manually write out each row.

<table>
    <tr>
        <th>Name</th>
        <th>Email</th>
    </tr>
    <?php
    $users = [
        ['John Doe', 'john@example.com'],
        ['Jane Smith', 'jane@example.com'],
        ['Mike Johnson', 'mike@example.com']
    ];

    for ($i = 0; $i < count($users); $i++) {
        echo '<tr>';
        echo '<td>' . $users[$i][0] . '</td>';
        echo '<td>' . $users[$i][1] . '</td>';
        echo '</tr>';
    }
    ?>
</table>