CKTIS / PHP
RecursiveArrayIterator
Expose nested arrays through hasChildren and getChildren, one level at a time.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
new RecursiveArrayIterator($array, RecursiveArrayIterator::CHILD_ARRAYS_ONLY)Expose nested arrays through hasChildren and getChildren, one level at a time. CHILD_ARRAYS_ONLY limits descent to arrays so object properties are not visited as children. Iterating the wrapper itself does not automatically flatten the full tree.
$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]
Examples
<?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()]);
Result
[["x",7],false]