php 获取某个目录下所有php文件

function getAllFileName($dir = null){
    if (empty($dir)){
        $dir = __DIR__;
    }
    $data = [];
    $allFile = scandir($dir);
    foreach ($allFile as &$item){
        if ($item == '.' || $item == '..'){
            continue;
        }
        if (is_dir($dir.'/'.$item)){
            $arr = getAllFileName($dir.'/'.$item);
            if (!empty($arr)){
                 $data = array_merge($data, $arr);
            }
        } else {
           if (substr($item, -4, 4) == '.php'){
               $data[] = $dir.'/'.$item;
           }
        }
    }
    return $data;
}

 

posted @ 2020-04-28 17:16  大道至简,小而蕴真  阅读(309)  评论(0编辑  收藏  举报