Home >Backend Development >PHP Tutorial >How to randomly display images in a specified folder in php, _PHP tutorial
This article describes an example of how to randomly display images in a specified folder in php. Share it with everyone for your reference. The details are as follows:
This code will randomly select an image from the specified server folder to display, which is very useful. The image format is .gif, .jpg, .png
<?php //This will get an array of all the gif, jpg and png images in a folder $img_array = glob("/path/to/images/*.{gif,jpg,png}",GLOB_BRACE); //Pick a random image from the array $img = array_rand($img_array); //Display the image on the page echo '<img alt="'.$img_array[$img].'" src="'.$img_array[$img].'" />'; ?>
I hope this article will be helpful to everyone’s PHP programming design.