3v4l.org

run code in 300+ PHP versions simultaneously
<?php function rotate(iterable $iterable, callable $predicate) { $tail = []; $match = false; foreach ($iterable as $key => $value) { if ($match || $predicate($value)) { yield $key => $value; $match = true; } else { $tail[] = [$key, $value]; } } foreach ($tail as [$key, $value]) { yield $key => $value; } } function gen() { yield 1; yield 2; yield 3; yield 4; yield 5; } $res = rotate(gen(), function($el) { return $el === 3; }); var_dump(iterator_to_array($res)); // [3, 4, 5, 1, 2]
Output for git.master, git.master_jit, rfc.property-hooks
array(5) { [2]=> int(3) [3]=> int(4) [4]=> int(5) [0]=> int(1) [1]=> int(2) }

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:
21.25 ms | 1950 KiB | 4 Q