zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    离线存储
    创业公司 加入
    console 代理
    HTTP 协议中 Vary 的一些研究
    reactNative 的一些学习
    srcset 图片自适应
    一些不错的文章分享
    前端网站大全
    c# 捕捉键盘按键
    SQL 中With as 的用法
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/8996134.html
Copyright © 2011-2022 走看看