略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: RecursiveTreeIterator

2024-12-21

The RecursiveTreeIterator class

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

简介

Allows iterating over a RecursiveIterator to generate an ASCII graphic tree.

类摘要

class RecursiveTreeIterator extends RecursiveIteratorIterator {
/* 继承的常量 */
/* 常量 */
const int BYPASS_CURRENT = 4;
const int BYPASS_KEY = 8;
const int PREFIX_LEFT = 0;
const int PREFIX_MID_HAS_NEXT = 1;
const int PREFIX_MID_LAST = 2;
const int PREFIX_END_HAS_NEXT = 3;
const int PREFIX_END_LAST = 4;
const int PREFIX_RIGHT = 5;
/* 方法 */
public __construct(
    RecursiveIterator|IteratorAggregate $iterator,
    int $flags = RecursiveTreeIterator::BYPASS_KEY,
    int $cachingIteratorFlags = CachingIterator::CATCH_GET_CHILD,
    int $mode = RecursiveTreeIterator::SELF_FIRST
)
public beginChildren(): void
public callHasChildren(): bool
public current(): mixed
public endChildren(): void
public endIteration(): void
public getEntry(): string
public getPostfix(): string
public getPrefix(): string
public key(): mixed
public next(): void
public nextElement(): void
public rewind(): void
public setPostfix(string $postfix): void
public setPrefixPart(int $part, string $value): void
public valid(): bool
/* 继承的方法 */
public RecursiveIteratorIterator::setMaxDepth(int $maxDepth = -1): void
}

预定义常量

RecursiveTreeIterator::BYPASS_CURRENT

RecursiveTreeIterator::BYPASS_KEY

RecursiveTreeIterator::PREFIX_LEFT

RecursiveTreeIterator::PREFIX_MID_HAS_NEXT

RecursiveTreeIterator::PREFIX_MID_LAST

RecursiveTreeIterator::PREFIX_END_HAS_NEXT

RecursiveTreeIterator::PREFIX_END_LAST

RecursiveTreeIterator::PREFIX_RIGHT

目录

add a noteadd a note

User Contributed Notes 1 note

up
22
matthieu88160
5 years ago
$it = new RecursiveArrayIterator(array(1, 2, array(3, 4, array(5, 6, 7), 8), 9, 10));
$tit = new RecursiveTreeIterator($it);

foreach( $tit as $key => $value ){
    echo $value . PHP_EOL;
}

/* Will output

|-1
|-2
|-Array
| |-3
| |-4
| |-Array
| | |-5
| | |-6
| | \-7
| \-8
|-9
\-10

*/

官方地址:https://www.php.net/manual/en/class.recursivetreeiterator.php

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