Random Images : rand « Math « PHP






Random Images

 
<html>
 <head>
  <title>Random Images</title>
 </head>
 <body bgcolor = "#000000" >

 <?php
  srand( microtime() * 1000000 );
  $num = rand( 1, 4 );

  switch( $num )
  {
    case 1 : $car = "a.jpg"; $url="a.php";      break;
    case 2 : $car = "f.jpg"; $url="f.php";   break;
    case 3 : $car = "j.jpg"; $url = "j.php";  break;
    case 4 : $car = "p.jpg"; $url = "p.php"; break;
  }
  $banner = "<a href=\"$url\"> ";
  $banner.= "<img src=\"$car\"  ";
  $banner.= "width=\"380\" height=\"110\" border=\"0\" >";
  $banner.="</a>";
  echo( $banner );
 ?>

 </body>
</html>
  
  








Related examples in the same category

1.Dice Rolling Simulator
2.Generate random numbers (integer values) between 0 and MAX_RAND by calling rand() or mt_rand() without any arguments
3.int rand ( [int min, int max] ) returns random numbers
4.Random Numbers