Random image example

This example uses an array to store images and then produces a random number and display the image on the screen

<?php
//an array of 4 images in the same direcory as the script
$images = array(“a1.gif”,”a2.gif”,”a3.gif”,”a4.gif”);
//generate a random number
srand((double)microtime()*1000000);
$randomno = (rand()%4);
//display image
echo (“<img src=\”$images[$randomno]\”>”);
?>

LEAVE A REPLY

Please enter your comment!
Please enter your name here

*