CKTIS / PHP
RecursiveIteratorIterator
Projde strom RecursiveIterator bez vlastní rekurzivní smyčky.
Verze: PHP 8.4; repository runtime, production runtime not attested
Syntaxe
new RecursiveIteratorIterator($recursive, RecursiveIteratorIterator::LEAVES_ONLY)Projde strom RecursiveIterator bez vlastní rekurzivní smyčky. LEAVES_ONLY vydá listy, SELF_FIRST rodiče před potomky a CHILD_FIRST po nich. Klíče platí místně a mohou se opakovat v různých větvích.
$tree=new RecursiveArrayIterator(["a"=>["id"=>1],"b"=>["id"=>2]]);
$walk=new RecursiveIteratorIterator($tree); $rows=[];
foreach($walk as $k=>$v){$rows[]=[$walk->getDepth(),$k,$v];} echo json_encode($rows);
[[1,"id",1],[1,"id",2]]
Příklady
<?php
$tree=new RecursiveArrayIterator(["a"=>["id"=>1],"b"=>["id"=>2]]);
$walk=new RecursiveIteratorIterator($tree); $rows=[];
foreach($walk as $k=>$v){$rows[]=[$walk->getDepth(),$k,$v];} echo json_encode($rows);
Výsledek
[[1,"id",1],[1,"id",2]]