CKTIS / PHP
RecursiveArrayIterator
Expone niveles de un array anidado con hasChildren y getChildren.
Versión: PHP 8.4; repository runtime, production runtime not attested
Sintaxis
new RecursiveArrayIterator($array, RecursiveArrayIterator::CHILD_ARRAYS_ONLY)Expone niveles de un array anidado con hasChildren y getChildren. CHILD_ARRAYS_ONLY limita el descenso a arrays sin visitar propiedades de objetos. Recorrer solo el envoltorio no aplana todo el árbol.
$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]
Ejemplos
<?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]