RecursiveIteratorIterator::setMaxDepth

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

RecursiveIteratorIterator::setMaxDepth β€” Установка максимальной Π³Π»ΡƒΠ±ΠΈΠ½Ρ‹ влоТСнности

ОписаниС

public function RecursiveIteratorIterator::setMaxDepth(int $maxDepth = -1): void

Π—Π°Π΄Π°Ρ‘Ρ‚ ΠΌΠ°ΠΊΡΠΈΠΌΠ°Π»ΡŒΠ½ΡƒΡŽ Π³Π»ΡƒΠ±ΠΈΠ½Ρƒ влоТСнности элСмСнтов.

Π’Π½ΠΈΠΌΠ°Π½ΠΈΠ΅

Π€ΡƒΠ½ΠΊΡ†ΠΈΡŽ ΠΏΠΎΠΊΠ° Π½Π΅ Π·Π°Π΄ΠΎΠΊΡƒΠΌΠ΅Π½Ρ‚ΠΈΡ€ΠΎΠ²Π°Π»ΠΈ; для знакомства доступСн Ρ‚ΠΎΠ»ΡŒΠΊΠΎ список Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚ΠΎΠ².

Бписок ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ²

maxDepth

Максимально допустимая Π³Π»ΡƒΠ±ΠΈΠ½Π° влоТСнности. -1 снимаСт ΠΎΠ³Ρ€Π°Π½ΠΈΡ‡Π΅Π½ΠΈΠ΅ Π½Π° Π³Π»ΡƒΠ±ΠΈΠ½Ρƒ рСкурсии.

Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅ΠΌΡ‹Π΅ значСния

Ѐункция Π½Π΅ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ значСния послС выполнСния.

Ошибки

ВыбрасываСт ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ Exception, Ссли Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚ maxDepth мСньшС -1.

οΌ‹Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΡ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Π΅ΠΉ 2 notes

up
1
Anonymous ΒΆ
6 years ago
to only access the current folder:
$max_depth = 0;
up
1
Anonymous ΒΆ
6 years 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);