CKTIS / PHP
RecursiveArrayIterator
Expõe os níveis de um array aninhado com hasChildren e getChildren.
Versão: PHP 8.4; repository runtime, production runtime not attested
Sintaxe
new RecursiveArrayIterator($array, RecursiveArrayIterator::CHILD_ARRAYS_ONLY)Expõe os níveis de um array aninhado com hasChildren e getChildren. CHILD_ARRAYS_ONLY limita a descida a arrays sem visitar propriedades de objetos. Percorrer apenas o invólucro não achata toda a árvore.
$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]
Exemplos
<?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()]);
Resultado
[["x",7],false]