3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getValueRecursive(array $array, ...$keys) { foreach ($keys as $key) { if (!key_exists($key, $array)) { throw new Exception('key path invalid'); } $array = $array[$key]; } return $array; } $foo = [ 'a' => [ 'b' => [ 'c' => "Hallo Welt!" ] ] ]; try { var_export(getValueRecursive($foo, 'a', 'b', 'c')); echo "\n---\n"; var_export(getValueRecursive($foo, 'a', 'b')); echo "\n---\n"; var_export(getValueRecursive($foo, 0, 'b', 'c')); } catch (Exception $e) { echo 'Caught exception: ' . $e->getMessage(); }
Output for git.master, git.master_jit, rfc.property-hooks
'Hallo Welt!' --- array ( 'c' => 'Hallo Welt!', ) --- Caught exception: key path invalid

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:
28.5 ms | 405 KiB | 5 Q