3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $groupId; private $value; function __construct($groupId, $value) { $this->groupId = $groupId; $this->value = $value; } function getGroupId() { return $this->groupId; } }; $foos = [ new Foo(1, 'Bar'), new Foo(1, 'Ban'), new Foo(1, 'Bak'), new Foo(2, 'Gas'), new Foo(2, 'Gar'), ]; var_dump(array_reduce($foos, function($carry, $item){ if(!isset($carry[$item->getGroupId()])) { $carry[$item->getGroupId()] = []; } $carry[$item->getGroupId()][] = $item; return $carry; }, []));
Output for git.master, git.master_jit, rfc.property-hooks
array(2) { [1]=> array(3) { [0]=> object(Foo)#1 (2) { ["groupId":"Foo":private]=> int(1) ["value":"Foo":private]=> string(3) "Bar" } [1]=> object(Foo)#2 (2) { ["groupId":"Foo":private]=> int(1) ["value":"Foo":private]=> string(3) "Ban" } [2]=> object(Foo)#3 (2) { ["groupId":"Foo":private]=> int(1) ["value":"Foo":private]=> string(3) "Bak" } } [2]=> array(2) { [0]=> object(Foo)#4 (2) { ["groupId":"Foo":private]=> int(2) ["value":"Foo":private]=> string(3) "Gas" } [1]=> object(Foo)#5 (2) { ["groupId":"Foo":private]=> int(2) ["value":"Foo":private]=> string(3) "Gar" } } }

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:
113.55 ms | 407 KiB | 5 Q