3v4l.org

run code in 300+ PHP versions simultaneously
<?php function createArrayMap(iterable $input, string $indexKey, ?string $valueKey = null): array { $map = []; foreach ($input as $obj) { $arr = $obj; $mapKey = $arr[$indexKey]; $value = $valueKey !== null ? $arr[$valueKey] : $obj; if (!array_key_exists($mapKey, $map)) { $map[$mapKey] = []; } $map[$mapKey][] = $value; } return $map; } $data = [ [ 'key' => 'first', 'name' => 'Foo' ], [ 'key' => 'second', 'name' => 'Bar' ], null ]; var_dump(createArrayMap($data, 'key'));
Output for git.master, git.master_jit
Warning: Trying to access array offset on value of type null in /in/bRhDB on line 10 array(3) { ["first"]=> array(1) { [0]=> array(2) { ["key"]=> string(5) "first" ["name"]=> string(3) "Foo" } } ["second"]=> array(1) { [0]=> array(2) { ["key"]=> string(6) "second" ["name"]=> string(3) "Bar" } } [""]=> array(1) { [0]=> NULL } }
Output for rfc.property-hooks
Warning: Trying to access array offset on null in /in/bRhDB on line 10 array(3) { ["first"]=> array(1) { [0]=> array(2) { ["key"]=> string(5) "first" ["name"]=> string(3) "Foo" } } ["second"]=> array(1) { [0]=> array(2) { ["key"]=> string(6) "second" ["name"]=> string(3) "Bar" } } [""]=> array(1) { [0]=> NULL } }

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