loop through image folder and return the next 3 images each time
I currently have a folder of images I'm trying to loop through with an
AJAX call and I want to just return 3 at a time until the end, then start
over from the beginning.
I'm having issues coming up with the logic with the portion of starting
from the beginning if the end is reached.
This is currently what I have.
$images = glob("images/*.jpg");
// sort images by file time
usort($images, function($a, $b) {
return filemtime($a) < filemtime($b);
});
$images = array_slice($images, $start_pos, 3);
To slice the images into groups of 3 $start_pos would be at 0, then after
the first call, go up to 3 to return images 4,5,6. But currently, if I
don't have more than 3 images, setting $start_pos of 3 would return
nothing, instead of starting over.
No comments:
Post a Comment