PHP 8.6.0RC7 available for testing

RecursiveCachingIterator::getChildren

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

RecursiveCachingIterator::getChildren — Return the inner iterator's children as a RecursiveCachingIterator

Açıklama

public function RecursiveCachingIterator::getChildren(): ?RecursiveCachingIterator

Returns the children of the current element, wrapped in a RecursiveCachingIterator that has the same flags. The children are retrieved from the inner iterator when the iterator moves to the element, so the same object is returned until the iterator moves on.

Bağımsız Değişkenler

Bu işlevin bağımsız değişkeni yoktur.

Dönen Değerler

The children of the current element, as a RecursiveCachingIterator; or null if the current element has no children.

Örnekler

Örnek 1 Iterating over children

<?php
$iterator = new RecursiveCachingIterator(
    new RecursiveArrayIterator(['a' => 1, 'b' => ['c' => 2, 'd' => 3], 'e' => 4]),
    0
);

foreach ($iterator as $key => $value) {
    if (!$iterator->hasChildren()) {
        echo $key, ' = ', $value, "\n";
        continue;
    }

    echo $key, ":\n";
    $children = $iterator->getChildren();
    foreach ($children as $childKey => $childValue) {
        echo '  ', $childKey, ' = ', $childValue, $children->hasNext() ? '' : ' (last)', "\n";
    }
}
?>

Yukarıdaki örneğin çıktısı:

a = 1
b:
  c = 2
  d = 3 (last)
e = 4

Ayrıca Bakınız

+add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top