php随机显示图片代码
时间:2021-07-01 10:21:17
帮助过:52人阅读
php通过rand()函数产生随机数,这个函数可以产生一个指定范围的数字
这段代码通过产生的随机数,随机选择图片 - srand( microtime() * 1000000 );
- $num = rand( 1, 4 );
-
- switch( $num )
- {
- case 1: https://www.gxlcms.com/$image_file = "/home/images/alfa.jpg";
- break;
- case 2: https://www.gxlcms.com/$image_file = "/home/images/ferrari.jpg";
- break;
- case 3: https://www.gxlcms.com/$image_file = "/home/images/jaguar.jpg";
- break;
- case 4: https://www.gxlcms.com/$image_file = "/home/images/porsche.jpg";
- break;
- }
- echo "Random Image : ";
- ?>
|
php