How can PHP be used to display results in rows of 3 in a table format?

To display results in rows of 3 in a table format using PHP, you can use a loop to iterate through the results and create a new row every 3 items. You can achieve this by keeping track of the count of items displayed and inserting a new row when the count reaches 3.

<?php
$results = ["Result 1", "Result 2", "Result 3", "Result 4", "Result 5", "Result 6"];

echo "<table>";
$count = 0;
foreach ($results as $result) {
    if ($count % 3 == 0) {
        echo "<tr>";
    }
    echo "<td>$result</td>";
    $count++;
    if ($count % 3 == 0) {
        echo "</tr>";
    }
}
echo "</table>";
?>