3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // Because lol: https://github.com/alvaropinot/circular-iterator function circularIterator(Iterator $t) { while (true) { yield $t->current(); $t->next(); if (!$t->valid()) { $t->rewind(); } } } $iter = circularIterator( SplFixedArray::fromArray([1, 2, 3]) ); $iter->rewind(); var_dump($iter->current()); $iter->next(); var_dump($iter->current()); $iter->next(); var_dump($iter->current()); $iter->next(); var_dump($iter->current()); $iter->next();
based on 2arts
Output for 5.5.0 - 7.3.0
int(1) int(2) int(3) int(1)