CKTIS / PHP
RecursiveArrayIterator
Expose les niveaux d’un tableau imbriqué avec hasChildren et getChildren.
Version : PHP 8.4; repository runtime, production runtime not attested
Syntaxe
new RecursiveArrayIterator($array, RecursiveArrayIterator::CHILD_ARRAYS_ONLY)Expose les niveaux d’un tableau imbriqué avec hasChildren et getChildren. CHILD_ARRAYS_ONLY limite la descente aux tableaux en laissant de côté les propriétés d’objets. Parcourir uniquement l’enveloppe n’aplatit pas tout l’arbre.
$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]
Exemples
<?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()]);
Résultat
[["x",7],false]