What is the best practice for displaying images in a random order using PHP?

When displaying images in a random order using PHP, one approach is to first store the image filenames in an array, shuffle the array to randomize the order, and then loop through the array to display the images on the webpage.

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

// Shuffle the array to randomize the order
shuffle($images);

// Loop through the array to display the images
foreach ($images as $image) {
    echo '<img src="images/' . $image . '" alt="Random Image">';
}
?>