I was reading PHP’s Array man and I saw this:
<?php
// fill an array with all items from a directory
$handle = opendir('.');
while (false !== ($file = readdir($handle))) {
$files[] = $file;
}
closedir($handle);
?>
In the readdir man page, it says “Correctly way of looping”.
I’d like to know if there’s a difference between X !== false and false !== X. Thanks!
No, there’s no difference. The reason you’ll sometimes see
false == xinstead ofx == falseis that it helps prevent accidentally typingx = falsewhich is permissible in an if or loop structure but is probably not what you want.false = xis nonsensical, and will generate an error instead of silently assigning something.