to only access the current folder:
$max_depth = 0;
PHP - Manual: RecursiveIteratorIterator::setMaxDepth
2024-11-15
(PHP 5 >= 5.1.0, PHP 7, PHP 8)
RecursiveIteratorIterator::setMaxDepth — Set max depth
$maxDepth
= -1): voidSet the maximum allowed depth.
本函数还未编写文档,仅有参数列表。
maxDepth
The maximum allowed depth. -1
is used
for any depth.
没有返回值。
Emits an Exception if maxDepth
is less than -1
.
I didn't understand what to do with this statement:
RecursiveIteratorIterator::setMaxDepth ([ int $max_depth = -1 ] ) : void
So, after finding the answer, this is how you incorporate it (for anyone else who was stuck for a while like me!):
// define the depth of the tree to which you want to search
// where -1 = show all layers below the parent
// and 1 = show the first layer, etc, etc
$max_depth = -1;
// set the path to the directory
$this_directory
// do the search
$recursive = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this_directory));
// now adjust the contents to your desired depth
$recursive->setMaxDepth($max_depth);
官方地址:https://www.php.net/manual/en/recursiveiteratoriterator.setmaxdepth.php