I am newish to PHP and I am trying to cycle through an array and stop after 5 items.
I am using the following:
$images = ( $f->APIVer == "1.2.2" ) ? $images['Images'] : $images;
// Display the thumbnails and link to the medium image for each image
foreach ( $images as $index => $image) {
echo '<li><a href="'.$image['XLargeURL'].'"><img src="'.$image['TinyURL'].'" alt="thumbnail"/></li>';
}
while ( $index < 5 );
}
Although it does not seem to work…
Am I doing something wrong?
Thanks in advance
If the array has a zero based index you can do:
Otherwise you can add your own counter:
What you tried is another type of loop:
Or:
Another alternative would be a
forloop: