I am kinda new to PHP.
I am searching a way to make PHP showing 6 random JPG images from a directory, no matter what the imagename is. The other important thing is that all the displayed images should be different.
Do you have any idea what's the easiest way to do it? I know i should use the glob function, but how to limit the images to 6,random and non repeatable?
I have that as code for the moment:
<?php
$pictures = glob("images/gallery/*.jpg");
$no_pictures = count($pictures)-1;
$limit = $no_pictures-5;
for( $i = $no_pictures; $i >= $limit; $i--){
echo '<div class="col-md-4 col-sm-6 col-xs-12 wow fadeInUp">
<a class="thumb" href="'.$pictures[$i].'"><img src="'.$pictures[$i].'" alt="Gallery"/><span class="thumb_overlay"></span></a>
</div>';
}
?>
But on image refresh it's not displaying different images, it's just tooking random 6 and keep displaying them all the time.
Aucun commentaire:
Enregistrer un commentaire