I am new to php and it's my first language. So my question seems to be very basic.
First the basic concept of a while loop seems pretty clear to me. As long as i increment (i++) until the "crash condition" (i<10) becomes true.
But I realy wonder why the following code example without any explicit incrementation works.
$originals = "originale";
$thumbnails="thumbnails";
$directory = opendir($originale);
$images = array();
while(($file = readdir($directory)) !== false) {
if(preg_match("/\.jp?g$/i", $file)){
$images[] = $file;
}
}
echo "<pre>";
var_dump($images);
echo "</pre>";
closedir($directory);
Obviously I missed something. It seems to be magic. I would expect an enless loop which returns the first file... ?
I hope that despite my English (sorry for that) the question becomes clear. Many thanks in advance.
while-loops run while the condition inside their braces is true. the condition in this case is($file = readdir($directory)), which tries to assign a new filename from the directory to $file and - as a whole - returns false if there is no new file available. but: explanation of basic code is quite off-topic for SO - this is not a tutorial site. [search engine of your choice] provides quite a few which should be better suited for your needs.$fileis set to false.