CKTIS / PHP
IteratorIterator
Prilagođava izvor Traversable pokazivaču Iterator.
Verzija: PHP 8.4; repository runtime, production runtime not attested
Sintaksa
new IteratorIterator($traversable)Prilagođava izvor Traversable pokazivaču Iterator. Korisno uz IteratorAggregate kada su potrebni current, next i key. Prije ručnog čitanja na omotaču pozovite rewind. Podaci se ne kopiraju unaprijed u polje.
class Source implements IteratorAggregate { public function getIterator(): Traversable {yield "x"=>4;yield "y"=>8;} }
$it=new IteratorIterator(new Source()); $it->rewind(); $first=$it->key(); $it->next(); echo json_encode([$first,$it->key(),$it->current()]);
["x","y",8]
Primjeri
<?php
class Source implements IteratorAggregate { public function getIterator(): Traversable {yield "x"=>4;yield "y"=>8;} }
$it=new IteratorIterator(new Source()); $it->rewind(); $first=$it->key(); $it->next(); echo json_encode([$first,$it->key(),$it->current()]);
Rezultat
["x","y",8]