3v4l.org

run code in 300+ PHP versions simultaneously
<?php function map(array $array, array $keys) { $filter = function ($branch) { return $branch; }; foreach (array_reverse($keys) as $key) { $filter = function ($branch) use ($filter, $key) { switch ($key) { case '*': case '?': return array_map(function ($dimension) use ($filter) { return $filter($dimension); }, $branch); default: return $filter($branch)[$key]; } }; } return $filter($array); } $array = [ 'a' => [ 'b' => [ [ 'c' => 'foo', ], [ 'c' => 'bar', ], [ 'c' => 'qux', ], ], ], ]; $keys = ['a', 'b', '*', 'c']; var_dump(map($array, $keys));
Output for git.master, git.master_jit
Warning: Undefined array key "c" in /in/Bm8aX on line 19 Warning: Undefined array key "b" in /in/Bm8aX on line 19 Warning: Trying to access array offset on value of type null in /in/Bm8aX on line 19 NULL
Output for rfc.property-hooks
Warning: Undefined array key "c" in /in/Bm8aX on line 19 Warning: Undefined array key "b" in /in/Bm8aX on line 19 Warning: Trying to access array offset on null in /in/Bm8aX on line 19 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:
42.35 ms | 401 KiB | 8 Q