Znalostní bázeCentrum zkoušek
CSČeština
Vybrat jazyk13

CKTIS / PHP

RecursiveArrayIterator

Zpřístupní úrovně vnořeného pole přes hasChildren a getChildren.

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

Syntaxe

new RecursiveArrayIterator($array, RecursiveArrayIterator::CHILD_ARRAYS_ONLY)

Zpřístupní úrovně vnořeného pole přes hasChildren a getChildren. CHILD_ARRAYS_ONLY omezí sestup na pole a vynechá vlastnosti objektů. Průchod samotným obalem nezploští celý strom.

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

Příklady

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

Výsledek

[["x",7],false]

Zdroje