Is it possible to use the rand function in PHP to display a new image every 10 seconds?

To display a new image every 10 seconds using the rand function in PHP, you can create an array of image file paths, use the rand function to select a random image from the array, and then use JavaScript to refresh the image every 10 seconds.

<?php
$images = ['image1.jpg', 'image2.jpg', 'image3.jpg']; // Array of image file paths
$random_image = $images[rand(0, count($images) - 1)]; // Select a random image from the array

echo '<img src="' . $random_image . '" id="randomImage">'; // Display the random image

echo '<script>
    setInterval(function() {
        var images = ' . json_encode($images) . ';
        var randomImage = images[Math.floor(Math.random() * images.length)];
        document.getElementById("randomImage").src = randomImage;
    }, 10000); // Refresh the image every 10 seconds
</script>';
?>