How can a new line be added after every 10 images are displayed in the PHP code?

To add a new line after every 10 images are displayed in PHP, you can use a counter variable to keep track of the number of images displayed. Once the counter reaches 10, you can echo a new line character to create the line break.

<?php
$counter = 0;
$images = array("image1.jpg", "image2.jpg", "image3.jpg", "image4.jpg", "image5.jpg", "image6.jpg", "image7.jpg", "image8.jpg", "image9.jpg", "image10.jpg", "image11.jpg", "image12.jpg");

foreach ($images as $image) {
    echo "<img src='$image' alt='image'>";
    $counter++;

    if ($counter == 10) {
        echo "<br>";
        $counter = 0;
    }
}
?>