3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_group(array $array, callable|string $callback): array { $groups = []; if (!is_callable($callback)) { return $groups; } foreach ($array as $key => $value) { $groups[call_user_func($callback, $value)][$key] = $value; } return $groups; } $people = [ ["name" => "Billy Jean", "filter" => false], ["name" => "Ronald Reagan", "filter" => true], ["name" => "Bill Clinton", "filter" => true], ["name" => "Michael Jackson", "filter" => false], ["name" => "Johnny Cash", "filter" => false], ]; var_export( array_group( $people, fn($p) => substr($p["name"], 0, 4) ) );
Output for git.master, git.master_jit, rfc.property-hooks
array ( 'Bill' => array ( 0 => array ( 'name' => 'Billy Jean', 'filter' => false, ), 2 => array ( 'name' => 'Bill Clinton', 'filter' => true, ), ), 'Rona' => array ( 1 => array ( 'name' => 'Ronald Reagan', 'filter' => true, ), ), 'Mich' => array ( 3 => array ( 'name' => 'Michael Jackson', 'filter' => false, ), ), 'John' => array ( 4 => array ( 'name' => 'Johnny Cash', 'filter' => false, ), ), )

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