Here is a code: <?php $directory = "lala"; $d = opendir($directory) or die ("couldn't access $directory"); while(!($file = readdir($d)) === false){ echo $file."<BR>"; } ?> PHP: Don't understand this place: while(!($file = readdir($d)) === false) PHP: Can somebody explain? Thank you very much.
readdir() "Returns the filename on success, or FALSE on failure. " while(!($file = readdir($d)) === false){ echo $file."<BR>"; Code (markup): this means keep printing out the file names till there are no more, (until readdir() returns false)
I don't understand why is while(!($file = readdir($d)) === false), but why is not while(!($file = readdir($d)) === true)
while(!($file = readdir($d)) === false) Code (markup): Translates to: while(Not($file) is exactly equal too false) (false being boolean 0, not a string) ! means not, and === means exactly equal (the same value and the same type) == would work fine unless there was a file named "false" or "0".
Sorry, one more question, why doesnt work this code: <?php $directory = "lala"; $d = opendir($directory) or die ("couldn't access $directory"); while($file = readdir($d) === true){ echo $file."<BR>"; } ?> PHP:
because you are saying: while($file === true) and $file equals the name of the file it's reading, or false when there are no more files. It never equals true, so the code in the loop will never execute. Edit: posted @ the same time nico_swd