The PHP Online Conference 2021

RecursiveIteratorIterator::setMaxDepth

(PHP 5 >= 5.1.0, PHP 7)

RecursiveIteratorIterator::setMaxDepthSet max depth

Descrierea

public RecursiveIteratorIterator::setMaxDepth ([ int $max_depth = -1 ] ) : void

Set the maximum allowed depth.

Avertizare

Această funcție nu este documentată în prezent; este disponibilă numai lista sa de argumente.

Parametri

max_depth

The maximum allowed depth. -1 is used for any depth.

Valorile întoarse

Nu este întoarsă nici o valoare.

Erori/Excepții

Emits an Exception if max_depth is less than -1.

add a note add a note

User Contributed Notes 2 notes

up
0
Anonymous
8 months ago
to only access the current folder:
$max_depth = 0;
up
0
Anonymous
8 months ago
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);
To Top