How can the PHP code be modified to display 3 images per row as requested by the forum user?

To display 3 images per row, we can modify the PHP code to add a counter that resets after every third image is displayed. When the counter reaches 3, we can add a line break to start a new row. This will ensure that only 3 images are displayed per row.

<?php
$images = array("image1.jpg", "image2.jpg", "image3.jpg", "image4.jpg", "image5.jpg", "image6.jpg");

echo "<div class='image-gallery'>";
$counter = 0;

foreach ($images as $image) {
    if ($counter % 3 == 0) {
        echo "<div class='row'>";
    }

    echo "<div class='image'><img src='$image' alt='Image'></div>";

    $counter++;

    if ($counter % 3 == 0) {
        echo "</div>";
    }
}

echo "</div>";
?>