3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [[ "continent" => "Europa", "country" => "France", "capital" => "Paris", ],[ "continent" => "Europa", "country" => "Spain", "capital" => "Madrid", ],[ "continent" => "Asia", "country" => "Russia", "capital" => "Moscow", ]]; $groupByProperty = function(array $list, string $property) { return array_reduce($list, function($grouped, $item) use(&$property) { $grouped[$item[$property]][] = $item; return $grouped; }, []); }; $groupedByContinent = $groupByProperty($data, 'continent'); var_dump($groupedByContinent);
Output for git.master, git.master_jit, rfc.property-hooks
array(2) { ["Europa"]=> array(2) { [0]=> array(3) { ["continent"]=> string(6) "Europa" ["country"]=> string(6) "France" ["capital"]=> string(5) "Paris" } [1]=> array(3) { ["continent"]=> string(6) "Europa" ["country"]=> string(5) "Spain" ["capital"]=> string(6) "Madrid" } } ["Asia"]=> array(1) { [0]=> array(3) { ["continent"]=> string(4) "Asia" ["country"]=> string(6) "Russia" ["capital"]=> string(6) "Moscow" } } }

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:
19.74 ms | 402 KiB | 8 Q