3v4l.org

run code in 300+ PHP versions simultaneously
<?php $deep = ['a' => ['b' => ['c' => 5]]]; function set(array $array, array $keys, $value) { while ($key = array_pop($keys)) { $value = [$key => $value]; } return array_replace_recursive($array, $value); } function get(array $array, array $keys, $default = null) { while ($key = array_shift($keys)) { if (!isset($array[$key])) { return $default; } $array = $array[$key]; } return $array; } $test = set($deep, ['a', 'b', 'c'], 15); $value = get($test, ['a', 'b', 'c'], 'spaghetti'); var_dump($deep); var_dump($test); var_dump($value);
Output for git.master, git.master_jit, rfc.property-hooks
array(1) { ["a"]=> array(1) { ["b"]=> array(1) { ["c"]=> int(5) } } } array(1) { ["a"]=> array(1) { ["b"]=> array(1) { ["c"]=> int(15) } } } int(15)

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:
57.38 ms | 401 KiB | 8 Q