Display the image Randomly using php

This post is used to display the images Randomly using php code. Randomly means it displays the image when u refresh the page it displays another image again u refresh the page you can get another image like this you can display the images randomly using php.

Code:

<?php
  srand( microtime() * 10 );
  $num = rand( 1, 4 );
   
  switch( $num ) 
  {
  case 1: $image_file = "1.jpg";
          break;
  case 2: $image_file = "2.jpg";
          break;
  case 3: $image_file = "3.jpg";
          break;
  case 4: $image_file = "4.jpg";
          break;
  }
  echo "<img src=$image_file />";
?>
</body>
</html>



Post a Comment

0 Comments