3v4l.org

run code in 300+ PHP versions simultaneously
<?php // test data class Foo { private $a; private $b; function __construct($a, $b) { $this->a = $a; $this->b = $b; } public function getA() { return $this->a; } public function getB() { return $this->b; } } $list = [ $foo1 = new Foo(2, "bar"), $foo2 = new Foo(5, "baz"), $foo3 = new Foo(1, "bam"), ]; // simple $isGreater = function($carry, $item) { return is_null($carry) || $item->getA() > $carry->getA() ? $item : $carry; }; $maxOfList = array_reduce($list, $isGreater); assert($maxOfList === $foo2); // reusable max() function $max = function($list, callable $extract) { $compare = function($carry, $item) use($extract) { return is_null($carry) || $extract($item) > $extract($carry) ? $item : $carry; }; return array_reduce($list, $compare); }; $extractA = function($x) { return $x->getA();}; assert($max($list, $extractA) === $foo2);
Output for git.master, git.master_jit, rfc.property-hooks

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