3v4l.org

run code in 300+ PHP versions simultaneously
<?php function printer() { for ($i = 0; $i < 10; $i++) { $string = (yield $i); var_dump($string); } } $printer = printer(); echo 'current: '; var_dump($printer->current()); $printer->send('Hello world!'); echo 'current: '; var_dump($printer->current()); $printer->next(); echo 'current: '; var_dump($printer->current()); $printer->send('Bye world!'); echo 'current: '; var_dump($printer->current());
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.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.26, 8.3.0 - 8.3.14, 8.4.1
current: int(0) string(12) "Hello world!" current: int(1) NULL current: int(2) string(10) "Bye world!" current: int(3)

preferences:
62.44 ms | 407 KiB | 5 Q