Baza wiedzyCentrum egzaminacyjne
PLPolski
Wybierz język13

CKTIS / PHP

RecursiveArrayIterator

Udostępnia poziomy zagnieżdżonej tablicy przez hasChildren i getChildren.

Wersja: PHP 8.4; repository runtime, production runtime not attested

Składnia

new RecursiveArrayIterator($array, RecursiveArrayIterator::CHILD_ARRAYS_ONLY)

Udostępnia poziomy zagnieżdżonej tablicy przez hasChildren i getChildren. CHILD_ARRAYS_ONLY ogranicza przejścia w dół do tablic, pomijając właściwości obiektów. Sam przebieg opakowania nie spłaszcza całego drzewa.

$it=new RecursiveArrayIterator(["group"=>["x"=>7],"value"=>(object)["y"=>2]],RecursiveArrayIterator::CHILD_ARRAYS_ONLY);
$it->rewind(); $child=$it->getChildren(); $child->rewind(); $first=[$child->key(),$child->current()]; $it->next(); echo json_encode([$first,$it->hasChildren()]);
[["x",7],false]

Przykłady

<?php
$it=new RecursiveArrayIterator(["group"=>["x"=>7],"value"=>(object)["y"=>2]],RecursiveArrayIterator::CHILD_ARRAYS_ONLY);
$it->rewind(); $child=$it->getChildren(); $child->rewind(); $first=[$child->key(),$child->current()]; $it->next(); echo json_encode([$first,$it->hasChildren()]);

Wynik

[["x",7],false]

Źródła