Znalostná bázaCentrum skúšok
SKSlovenčina
Vybrať jazyk13

CKTIS / PHP

RecursiveArrayIterator

Sprístupní úrovne vnoreného poľa cez hasChildren a getChildren.

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

Syntax

new RecursiveArrayIterator($array, RecursiveArrayIterator::CHILD_ARRAYS_ONLY)

Sprístupní úrovne vnoreného poľa cez hasChildren a getChildren. CHILD_ARRAYS_ONLY obmedzí zostup na polia a vynechá vlastnosti objektov. Prechod samotným obalom nesploš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]

Prí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ýsledok

[["x",7],false]

Zdroje