3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Queue { private $queue = []; public function add($var) { $this->queue[] = $var; } public function take(): \Generator { while($var = array_shift($this->queue)) { if($var instanceof Queue) { yield from $var->take(); } else { yield $var; } } } } $subQueue = new Queue(); $subQueue->add('A'); $subQueue->add('B'); $subQueue->add('C'); $queue = new Queue(); $queue->add('a'); $queue->add('b'); $queue->add('c'); $queue->add($subQueue); $queue->add('d'); foreach($queue->take() as $index => $item) { echo $index; if($index === 1) { $queue->add('hello'); } var_dump($item); }
Output for git.master, git.master_jit, rfc.property-hooks
0string(1) "a" 1string(1) "b" 2string(1) "c" 0string(1) "A" 1string(1) "B" 2string(1) "C" 3string(1) "d" 4string(5) "hello" 5string(5) "hello"

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
106.39 ms | 405 KiB | 5 Q