3v4l.org

run code in 300+ PHP versions simultaneously
<?php // thanks to metaultralurker on reddit for inspiration function map(callable $fn, \Traversable $data) { foreach ($data as $v) { yield $fn($v); } } function filter(callable $fn, \Traversable $data) { foreach ($data as $v) { if ($fn($v)) { yield $v; } } } function infinite_range() { $i = 0; while (true) { yield $i++; } } function take($n, \Traversable $data) { $i = 0; foreach ($data as $v) { if ($i++ === $n) { break; } yield $v; } } function reduce(callable $fn, \Traversable $data, $runningTotal = null) { $first = true; foreach ($data as $v) { if (null === $runningTotal && $first) { $runningTotal = $v; continue; } $runningTotal = $fn($runningTotal, $v); $first = false; } return $runningTotal; } $isEven = function ($x) { return $x % 2 == 0; }; $data = take(10, map('floatval', filter($isEven, infinite_range()))); /* var_dump($data->current()); $data->next(); var_dump($data->current()); $data->next(); */ // var_dump(iterator_to_array($data)); $concat = function ($sep, $a, $b) { return $a.$sep.$b; }; $concatComma = function ($a, $b) use ($concat) { return $concat(',', $a, $b); }; var_dump(reduce($concatComma, $data));
Output for git.master, git.master_jit, rfc.property-hooks
string(24) "0,2,4,6,8,10,12,14,16,18"

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:
54.75 ms | 401 KiB | 8 Q