随机图像显示 [英] random images display

查看:113
本文介绍了随机图像显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在输出多个图片时,最简单的代码或方法是什么?

What is the simplest code or method to use when it comes to outputting multiple images?

此外,我想在css文件中设置样式。

Plus I want to style it in my css file.

我要在我的index.php上显示它们

I want to display them on my index.php

我已经尝试过了:
随机图片显示

如何使这些图片随机显示一次一个使用php或javascript或html:

How do I make these images display randomly one at a time using php or javascript or html:

<img src="image_1"/>
<img src="image_2"/>
<img src="image_3"/>
<img src="image_4"/>
<img src="image_5"/>


推荐答案

你应该创建一个像这样的图像数组: / p>

You should make an array of images like that:

<?php
    $images = array('img1.jpg', 'img2.jpg', 'img3.jpg');
?>

然后,您只需从数组中获取一个随机元素

Then, you just get a random element from the array

<?php
    $random_image = array_rand($images);
?>

然后您可以立即显示图片:

Then you can go right away displaying the image:

<img src="<?php echo $images[$random_image]; ?>" />

希望这有帮助。

这篇关于随机图像显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆