递归扫描目录内容
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了递归扫描目录内容相关的知识,希望对你有一定的参考价值。
<?php function dir_recursive($path, $parent = ''){ while (false !== ($entry = $d->read())) { if($entry == '.' || $entry == '..') continue; //if this is a directory, loop inside its contents //if parent dir given, then create another array dimension to be used to store files under this parent $files[$parent][$entry] = dir_recursive($d->path.'/'.$entry, $entry); }else $files[$entry] = dir_recursive($d->path.'/'.$entry, $entry); }else $files[$entry] = $entry; //reset parent dir given, so it won't create another array dimension for the next loop of subdirectory $parent = ''; } $d->close(); return $files; } //usage $files = dir_recursive('.'); ?>
以上是关于递归扫描目录内容的主要内容,如果未能解决你的问题,请参考以下文章