What are best practices for structuring PHP code in a while loop for image display?

When displaying images in a while loop in PHP, it's important to structure your code efficiently to avoid unnecessary repetition and improve readability. One best practice is to separate the HTML markup from the PHP logic by using PHP to generate the necessary HTML code for each image. This can be achieved by looping through an array of image URLs and echoing out the HTML code within the loop.

<?php
// Array of image URLs
$images = array("image1.jpg", "image2.jpg", "image3.jpg");

// Display images using a while loop
foreach ($images as $image) {
    echo '<img src="' . $image . '" alt="Image">';
}
?>