Or use the for loop statement mentioned in the subject line....
for($i=0; $i<3; $i++)
{
$v = each($MyImages);
//...
}
$MyImages might not have that many elements.
for($i=0; $i<min(3, count($MyImages)); $i++)
But that makes for extra work (the count and min both get checked three times)
for($i=0, $count=min(3, count($MyImages)); $i<$count; $i++)
If this isn't going to be called multiple times to list images in $MyImages three at a time, then a temporary array might be useful
$threeImages = array_slice($MyImages, 0, 3);
for($i=0; $i<count($threeImages); $i++)
Since we're going to be looping over all of the elements in $threeImages we don't really need to keep count any more:
foreach($threeImages as $v)
Since this is the only place where $threeImages would be used
foreach(array_slice($MyImages, 0, 3) as $v)
If it is going to be called multiple times, then 0 would be replaced by a counter that starts at 0 and increases by 3 each time. Or the whole $MyImages array could be array_chunk()ed, with an outer loop going through the chunks and an inner loop going through the contents of each chunk.