How can the code snippet be optimized to ensure that all images are displayed correctly, not just one specific image?

The issue with the current code snippet is that it is only checking for one specific image file name, which may not be applicable to all images. To ensure that all images are displayed correctly, we can modify the code to dynamically retrieve the image file names from the specified directory and display them accordingly.

<?php
$directory = "images/"; // Specify the directory where images are stored
$images = glob($directory . "*.{jpg,jpeg,png,gif}", GLOB_BRACE); // Get all image file names in the directory

foreach ($images as $image) {
    echo '<img src="' . $image . '" alt="Image">';
}
?>