Hello, I need to create a function that makes 3 images change the position randomly every time a page is refreshed. The picture explains it better.
Hey there, You could try something like this I guess: <?php $images = array("image1.jpg", "image2.jpg", "image3.jpg"); shuffle($images); foreach($images as $i) { echo '<img src="' . $i . '">'; } ?> Code (markup): Hope that helps Francisco
Francisco's code should work just fine, but here is the valid XHTML version, just incase you worried about that stuff. <?php $images = array("image1.jpg", "image2.jpg", "image3.jpg"); shuffle($images); foreach($images as $i) { echo '<img src="' . $i . '" alt="" />'; } ?> Code (markup):
Thanks for the replies! Btw I wrote a big function in PHP to do that before seeing your tips, but at least now I know the easy way