Jump to content

PHP random images in set positions?


Andrew2010

Recommended Posts

Wrong forum.

 

How do you want to randomly load the image? If you have your images in the same directory and named like "image_1.jpg", "image_2.jpg", "image_3.jpg", and so on, you could do something like this:

 

<?php

// Generate a random number
$number = mt_rand(1, 3); // Change the "3" to the number of images available

// Print the random image on the page, wherever you want it positioned
echo '<img src="image_' . $number . '.jpg" alt="Picture!" />';

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.