3v4l.org

run code in 300+ PHP versions simultaneously
<?php function stack(... $items) { foreach ($items as $item) { $next = yield; if ($next) { yield from stack(... $next); } yield $next; } } $items = [1,2,3]; $stack = stack(...$items); foreach ($stack as $item) { if ($item == 1) { $stack->send(['negate', -$item]); } if ($item == 3) { $stack->send(['exponential', $item ** 2]); } var_dump($item); }
Output for 7.0.0 - 7.0.33, 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.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
NULL NULL NULL NULL NULL NULL
Output for 5.6.0 - 5.6.40
Parse error: syntax error, unexpected 'stack' (T_STRING) in /in/grEUi on line 8
Process exited with code 255.

preferences:
179.56 ms | 401 KiB | 283 Q