random - shuffle order of images in php -
i have following images in i'm using carousel. each time page loads want them in in different order. thinking of ordering numbers using random number generator, i'm not sure how make numbers used once. if done in loop it's expandable great.
see static code below, images named same except number @ end
<div class="image-entry"> <img src="/images/carousel-1.jpg" /> </div> <div class="image-entry"> <img src="/images/carousel-2.jpg" /> </div> <div class="image-entry"> <img src="/images/carousel-3.jpg" /> </div> <div class="image-entry"> <img src="/images/carousel-4.jpg" /> </div>
thanks!
there function that, shuffle()
:
$images = array ( '/images/carousel-1.jpg', '/images/carousel-2.jpg', '/images/carousel-3.jpg', '/images/carousel-4.jpg', ); shuffle($images); // magic foreach ($images $image) { echo '<div class="image-entry">'; echo "\t" . '<img src="' . $image . '" />'; echo '</div>'; }
Comments
Post a Comment