Hi group, I have this small script that uses array_rand to pick a picture out of a directory and display it. The problem is, alot of the time, the very same image is displayed in the next refresh or within the next 5 refreshes for sure. This is out of a 100 images.
What I was hoping is someone could devise a way to not allow the same picture to display within x amount of refreshes, kind of temporarily remove the image from the array.
Here is the code I am using.
[php]
<?php /******************************************************************************* * SETTINGS * * See readme.htm file for further instructions! *******************************************************************************/ /* The default folder with images */ $settings['img_folder'] = 'images/'; /* File types (extensions) to display */ $settings['img_ext'] = array('.jpg','.gif','.png'); /* How to display the images? 0 = print just the image path (for includes), like: images/test.jpg 1 = redirect to the image, when using:[/php]
I found an idea by googling but I couldn’t figure out how to apply it to this script. Here is what someone proposed that seemed to have some success for another user.
[php]
$style_class = array(“st_style1”,“st_style2”,“st_style3”,“st_style4”);
$styles = array()
$lastStyle = -1
for($i = 0; $i < 5; $i++) {
while(1==1) {
$newStyle = array_rand($style_class, 1);
if ($lastStyle != $newStyle) {
$lastStyle = $newStyle;
break;
}
}
$div_class = $style_class[$lastStyle]
$styles[] = $div_class
}
[/php]
Thanks if you can help me.