Baza znanjaCentar za ispite
HRHrvatski
Odaberi jezik13

CKTIS / PHP

RecursiveArrayIterator

Izlaže razine ugniježđenog polja preko hasChildren i getChildren.

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

Sintaksa

new RecursiveArrayIterator($array, RecursiveArrayIterator::CHILD_ARRAYS_ONLY)

Izlaže razine ugniježđenog polja preko hasChildren i getChildren. CHILD_ARRAYS_ONLY ograničava spuštanje na polja i preskače svojstva objekata. Obilazak samo omotača ne izravnava cijelo stablo.

$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]

Primjeri

<?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()]);

Rezultat

[["x",7],false]

Izvori