random images display [closed]

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

Plus I want to style it in my css file.

I want to display them on my index.php

I have tried this already: Random image display

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"/>



You should make an array of images like that:

    $images = array('img1.jpg', 'img2.jpg', 'img3.jpg');

Then, you just get a random element from the array

    $random_image = array_rand($images);

Then you can go right away displaying the image:

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

Hope this helps.


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.