CKTIS / PHP
RecursiveArrayIterator
Espone i livelli di un array annidato con hasChildren e getChildren.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
new RecursiveArrayIterator($array, RecursiveArrayIterator::CHILD_ARRAYS_ONLY)Espone i livelli di un array annidato con hasChildren e getChildren. CHILD_ARRAYS_ONLY limita la discesa agli array e tralascia le proprietà degli oggetti. Scorrere il solo involucro non appiattisce l’intero albero.
$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]
Esempi
<?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()]);
Risultato
[["x",7],false]