CKTIS / PHP
RecursiveIteratorIterator
Obilazi stablo RecursiveIterator bez vlastite rekurzivne petlje.
Verzija: PHP 8.4; repository runtime, production runtime not attested
Sintaksa
new RecursiveIteratorIterator($recursive, RecursiveIteratorIterator::LEAVES_ONLY)Obilazi stablo RecursiveIterator bez vlastite rekurzivne petlje. LEAVES_ONLY daje listove, SELF_FIRST roditelja prije potomaka, a CHILD_FIRST poslije njih. Ključevi su lokalni i mogu se ponoviti u različitim granama.
$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]]
Primjeri
<?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);
Rezultat
[[1,"id",1],[1,"id",2]]