Random Image Selector

Tutorials for php.

Random Image Selector

Postby Mortisimus on Mon Aug 25, 2008 6:47 pm

Ok, here is a very simple way of selecting a random image using php.

Firstly, we create an array of images. This can be any amount of images, it doesn't matter.

Code: Select all
$images = array("image1.png", "image2.png", "image3.png");


Now we use the shuffle() function to select a random value from the array and return it.

Code: Select all
$value = shuffle($images);


Then we just echo out the image using the $value variable as the src.

Code: Select all
echo '<img src="' . $value . '" alt="Image" />';


Thanks for reading, I hope it helped.
User avatar
Mortisimus
Site Admin
 
Posts: 21
Joined: Mon Aug 25, 2008 6:04 pm

Return to PHP Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest

cron