Home  >  Article  >  Backend Development  >  PHP's readdir() function, phpreaddir function_PHP tutorial

PHP's readdir() function, phpreaddir function_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:05:531024browse

PHP's readdir() function, phpreaddir function

Recently I am learning the relevant knowledge of PHP file operations, and record one of the points to pay attention to in the readdir() function

1. In the $temp=readdir($handle) function, readdir obtains the file name and the folder name in $handle,

Generally, in a program, files are traversed through a while() loop:

         while($temp=readdir($handel)){}

  But there is a problem with the judgment statement written in this way: if there is a folder with the name '0' under $handle, then $temp=0, the while loop cannot proceed, and then the remaining files cannot be traversed. , resulting in incorrect program results,

Correct writing:

    while(($temp=readdir($handel))!==false){}//用不全等于是区分如果文件夹名字为0的时候,那么0!==false,仍然可以遍历

 

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1066608.htmlTechArticlePHP’s readdir() function, phpreaddir function. Recently, I am learning the relevant knowledge of php file operations. Record readdir() One of the points to note about the function 1. In the $temp=readdir($handle) function...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn