What about
$dir = "images";
opendir($dir);
$continue=true;
while ($continue) {
for ($x=0; $x<=5; $x++) {
$file = readdir($dh);
if ($file===false) {
$continue=false; //for the while
break; //for the for
}
echo $file . '<br>';
}
}
closedir($dir);
You could remove the need for the $continue
flag variable by using while($file!==false)
but at a cost on readability.