CKTIS / PHP
IteratorIterator
Přizpůsobí zdroj Traversable kurzoru Iterator.
Verze: PHP 8.4; repository runtime, production runtime not attested
Syntaxe
new IteratorIterator($traversable)Přizpůsobí zdroj Traversable kurzoru Iterator. Hodí se u IteratorAggregate, vyžaduje-li kód current, next a key. Před ručním čtením zavolejte na obalu rewind. Data se předem nekopírují do pole.
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]
Příklady
<?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()]);
Výsledek
["x","y",8]