PHP RecursiveIteratorIterator
似乎使我的网站在每个浏览器请求上都很慢。
我可以使用其他任何选项代替RecursiveIteratorIterator
吗?
或者我的代码中可能存在使用RecursiveIteratorIterator
无效的内容?
$mainDirectories = [
'local/app/',
'local/ioc/',
'local/controller/',
'local/model/',
'local/helper/'
]
foreach($mainDirectories as $pathDirectory)
{
$iterator = new RecursiveIteratorIterator
(
new RecursiveDirectoryIterator($pathDirectory),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $fileObject)
{
if ($fileObject->isDir())
{
// Replace any backslash to '/'.
$pathnameReplace = str_replace('\\', '/', $fileObject->getPathname());
//print_r($pathnameReplace);
// Explode the folder path.
$array = explode("/",$pathnameReplace);
// Get the actual folder.
$folder = end($array);
//print_r($folder);
// Stop proccessing if the folder is a dot or double dots.
if($folder === '.' || $folder === '..') {continue;}
//var_dump($fileObject->getPathname());
}
}
}
此代码用于列出每个主要目录中的子目录。例如,
'local / model /'中有子目录,
article/
nav/
结果将是,
array (size=2)
0 => string 'local/model/article/' (length=19)
1 => string 'local/model/nav/' (length=15)
等等。