CKTIS / PHP
RecursiveArrayIterator
Razkrije ravni ugnezdenega polja prek hasChildren in getChildren.
Različica: PHP 8.4; repository runtime, production runtime not attested
Sintaksa
new RecursiveArrayIterator($array, RecursiveArrayIterator::CHILD_ARRAYS_ONLY)Razkrije ravni ugnezdenega polja prek hasChildren in getChildren. CHILD_ARRAYS_ONLY omeji spust na polja in izpusti lastnosti objektov. Obhod samega ovoja ne splošči celotnega drevesa.
$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]
Primeri
<?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()]);
Rezultat
[["x",7],false]