Home >Backend Development >PHP Tutorial >php randomly displays image code

php randomly displays image code

WBOY
WBOYOriginal
2016-07-25 08:44:131552browse
PHP generates random numbers through the rand() function. This function can generate a number within a specified range.
This code randomly selects pictures through the generated random numbers
  1. srand( microtime() * 1000000 );
  2. $num = rand( 1, 4 );
  3. switch( $num )
  4. {
  5. case 1: $image_file = "/home/images/alfa.jpg";
  6. break;
  7. case 2: $image_file = "/home/images/ferrari.jpg";
  8. break;
  9. case 3: $image_file = "/home/images/jaguar.jpg";
  10. break;
  11. case 4: $image_file = "/home/images/porsche.jpg";
  12. break;
  13. }
  14. echo " Random Image : ";
  15. ?>
Copy code

php


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn