php[world] 2018 - Call for Speakers

RecursiveIteratorIterator::getDepth

(PHP 5, PHP 7)

RecursiveIteratorIterator::getDepthGet the current depth of the recursive iteration

Beschreibung

public int RecursiveIteratorIterator::getDepth ( void )
Warnung

Diese Funktion ist bis jetzt nicht dokumentiert. Es steht nur die Liste der Argumente zur Verf├╝gung.

Parameter-Liste

Diese Funktion hat keine Parameter.

R├╝ckgabewerte

The current depth of the recursive iteration.

add a note add a note

User Contributed Notes 1 note

up
1
spicypixel at gmail dot com
1 month 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;
}
?>
To Top