I have a folder containing images and echo them to the page.
This works fine however I want them to randomly change output upon page load.
This is the part that outputs the images:
<?php
$directory = 'somewhere/images/';
$files = getPathsByKind($directory,'svg');
if(!empty($files)) {
for($i=0; $i < 32; $i++){
echo '<img src="'.get_bloginfo('template_directory').'/images/'.$files[$i].'">';
}
}
?>
So I thought I'd had to use rand()
or array_rand()
but both throw me errors. Which is fine but I have no idea on how to fix them. rand()
throws me an second parameter error. (max
andmin
value). Since this is an image there is no second parameter. array_rand()
won't work because of the loop it isn't an Array
anymore.
Any idea on how to accomplish this?