php隨機顯示圖片代碼
php通過rand()函數產生隨機數,這個函數可以產生一個指定范圍的數字
這段代碼通過產生的隨機數,隨機選擇圖片
<html> <body> <?php srand( microtime() * 1000000 ); $num = rand( 1, 4 );switch( $num ) { case 1: $image_file = "/home/images/alfa.jpg"; break; case 2: $image_file = "/home/images/ferrari.jpg"; break; case 3: $image_file = "/home/images/jaguar.jpg"; break; case 4: $image_file = "/home/images/porsche.jpg"; break; } echo "Random Image : <img src=$image_file />"; ?> </body> </html></pre>
本文由用戶 phpw34 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!