bilis_money Posted June 26, 2006 Share Posted June 26, 2006 hi, PHP addicted?Can you tell me why the manual suggested the first while loop over the directory is the correct one?[code]<?php // This is the correct way to loop over the directory. while (false !== ($file = readdir($handle))) { echo "$file\n"; echo "<br>"; } // This is the WRONG way to loop over the directory. while ($file = readdir($handle)) { echo "$file<br>"; }?>[/code]Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/12915-comparing-directory-loop-codes/ Share on other sites More sharing options...
.josh Posted June 26, 2006 Share Posted June 26, 2006 they explain it right about the code:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--] Please note the fashion in which readdir()'s return value is checked in the examples below. We are explicitly testing whether the return value is identical to (equal to and of the same type as--see Comparison Operators for more information) FALSE since otherwise, any directory entry whose name evaluates to FALSE will stop the loop (e.g. a directory named "0").[/quote] Link to comment https://forums.phpfreaks.com/topic/12915-comparing-directory-loop-codes/#findComment-49591 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.