3v4l.org

run code in 300+ PHP versions simultaneously
<?php function gen() { yield from [0, 1, 2, 3, 4]; } $gen = (function(){ $foo = gen(); $foo->rewind(); $foo->valid(); yield $foo->key() => $foo->current(); $foo->next(); $foo->valid(); yield $foo->key() => $foo->current(); yield from $foo; })(); foreach($gen as $k => $v){ echo $k . " => " . $v . "\n"; }
Output for 7.4.6 - 7.4.30, 8.0.0 - 8.0.20, 8.1.0 - 8.1.7
0 => 0 1 => 1 1 => 1 2 => 2 3 => 3 4 => 4
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.5
0 => 0 1 => 1 2 => 2 3 => 3 4 => 4

preferences:
45.99 ms | 410 KiB | 5 Q