php实现遍历文件目录

php实现遍历文件目录

一、总结

1、熟悉简单:很经典的例子,多看,然后发现熟悉了很简单 

二、php实现遍历目录

php实现遍历目录

代码一:

 1 //遍历目录
 2 function iteral($path){
 3   $filearr = array();
 4   foreach (glob($path.'*') as $file){
 5     if(is_dir($file)){
 6       $filearr = array_merge($filearr,iteral($file));
 7     }else{
 8       $filearr[] = $file;
 9     }
10   }
11   return $filearr;
12 }
13 var_dump(iteral('d:www	est'));

1、第3行,定义的位置

2、第4行,php中.(点号)是连接符 

截图:

代码二:

 1 //遍历目录
 2 public function bianli($path){
 3     $ans=array();
 4     foreach(glob($path.'*') as $file){
 5         if(is_dir($file)){
 6             $ans=array_merge($ans,$this->bianli($file));
 7         }else{
 8             $ans[]=$file;
 9         }
10     }
11     return $ans;
12 }
13 public function bianliDemo(){
14     dump($this->bianli('e:JAVA'));
15 }
原文地址:https://www.cnblogs.com/Renyi-Fan/p/8996134.html