LonghornPHP 2026

RecursiveIteratorIterator::getDepth

(PHP 5, PHP 7, PHP 8)

RecursiveIteratorIterator::getDepthObtiene la profundidad actual de la recursividad del iterador

Descripción

public function RecursiveIteratorIterator::getDepth(): int
Advertencia

Esta función está actualmente no documentada; solo la lista de sus argumentos está disponible.

Parámetros

Esta función no contiene ningún parámetro.

Valores devueltos

La profundidad actual de la recursividad del iterador.

Found A Problem?

Learn How To Improve This PageSubmit a Pull RequestReport a Bug
+add a note

User Contributed Notes 1 note

up
4
spicypixel at gmail dot com
8 years ago
Example to only return directories that are a specified depth in a tree:
<?php
function directory_mapper($path)
{
 $maxDepth = 3;
 $minDepth = 3;
 $iterator = new RecursiveIteratorIterator(
 new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
 RecursiveIteratorIterator::SELF_FIRST,
 RecursiveIteratorIterator::CATCH_GET_CHILD// Ignore "Permission denied"
 );
 $iterator->setMaxDepth($maxDepth);
 $paths = array($path);
 foreach ($iterator as $path => $dir) {
 if ($iterator->getDepth() >= $minDepth) {
 if ($dir->isDir()) {
 $paths[] = $path;
 }
 }
 }
 array_shift($paths);
 return $paths;
}
?>
+add a note

AltStyle によって変換されたページ (->オリジナル) /