略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: RecursiveIteratorIterator::getDepth

2024-11-15

RecursiveIteratorIterator::getDepth

(PHP 5, PHP 7, PHP 8)

RecursiveIteratorIterator::getDepthGet the current depth of the recursive iteration

说明

public RecursiveIteratorIterator::getDepth(): int
警告

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

The current depth of the recursive iteration.

add a noteadd a note

User Contributed Notes 1 note

up
3
spicypixel at gmail dot com
4 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;
}
?>

官方地址:https://www.php.net/manual/en/recursiveiteratoriterator.getdepth.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3