I print img html elements by a foreach cycle.
Images are stored in db so if they are 40 foreach will print 40 img
Now i need that if they are 40 in db and i need to print 100 img elements, to repeat the cycle until they are 100, is it possible to do that?
EDIT:
to be clear, i retrieve 40 img from db, i need to print “100 OF THEM” (repeat them if they are less than 100) … hope is clear 😛
You can use Iterators:
The
ArrayIteratormakes your$imgArrayiterateable by other Iterators. TheInfiniteIteratorwill make the wrappedArrayIteratorstart over at the beginning when it has reached the end of$imgArray. Finally, theLimitIteratorwill limit the iteration to 100 items.So, when you iterate over
$images,foreachwill go over the elements in the image array repeating them over and over until 100 elements have been printed, e.g. this will output images 1-40, then again 1-40 and finally 1-20 because 40+40+20=100.Demo: http://codepad.org/YeDgpsVc