<?php
//方法一:使用glob循环
function myscandir1($path, &$arr) {
foreach (glob($path) as $file) {
if (is_dir($file)) {
myscandir1($file . '/*', $arr);
} else {
$arr[] = realpath($file);
}
}
}
?>
<?php
//方法二:使用dir && read循环
function myscandir2($path, &$arr) {
$dir_handle = dir($path);
while (($file = $dir_handle->read()) !== false) {
$p = realpath($path . '/' . $file);
if ($file != "." && $file != "..") {
$arr[] = $p;
}
if (is_dir($p) && $file != "." && $file != "..") {
myscandir2($p, $arr);
}
}
}
?>
<?php
//方法三:使用opendir && readdir循环
function myscandir3($path, &$arr) {
$dir_handle = opendir($path);
while (($file = readdir($dir_handle)) !== false) {
$p = realpath($path . '/' . $file);
if ($file != "." && $file != "..") {
$arr[] = $p;
}
if (is_dir($p) && $file != "." && $file != "..") {
myscandir3($p, $arr);
}
}
}
?>
<?php
//方法四:使用scandir循环
function myscandir4($path, &$arr) {
$dir_handle = scandir($path);
foreach ($dir_handle as $file) {
$p = realpath($path . '/' . $file);
if ($file != "." && $file != "..") {
$arr[] = $p;
}
if (is_dir($p) && $file != "." && $file != "..") {
myscandir4($p, $arr);
}
}
}
?>
<?php
//方法五:使用SPL循环
function myscandir5($path, &$arr) {
$iterator = new DirectoryIterator($path);
foreach ($iterator as $fileinfo) {
$file = $fileinfo->getFilename();
$p = realpath($path . '/' . $file);
if (!$fileinfo->isDot()) {
$arr[] = $p;
}
if ($fileinfo->isDir() && !$fileinfo->isDot()) {
myscandir5($p, $arr);
}
}
}
?>
<?php
myscandir1('./Code',$arr1);//0.164010047913
myscandir2('./Code',$arr2);//0.243014097214
myscandir3('./Code',$arr3);//0.233012914658
myscandir4('./Code',$arr4);//0.240014076233
myscandir5('./Code',$arr5);//0.329999923706
//需要安装xdebug
echo xdebug_time_index(), "\n";
?>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有