3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $path = 'foo/bar/baz'; $root = array('foo' => array('bar' => array('baz' => 'something'))); function bla(&$root, $path, $value) { $paths = explode('/', $path); $current = &$root; foreach ($paths as $path) { if (isset($current[$path])) { $current = &$current[$path]; } else { return null; } } return $current[$value] = $value; } bla($root, $path, '123'); var_dump($root);
Output for 5.2.1 - 5.2.9, 5.2.12 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(1) { ["foo"]=> array(1) { ["bar"]=> array(1) { ["baz"]=> string(124) "something 1" } } }
Output for 5.2.10 - 5.2.11
Notice: Uninitialized string offset: 123 in /in/iUm08 on line 19 array(1) { ["foo"]=> array(1) { ["bar"]=> array(1) { ["baz"]=> string(124) "something 1" } } }
Output for 4.3.0 - 5.2.0
array(1) { ["foo"]=> &array(1) { ["bar"]=> &array(1) { ["baz"]=> string(124) "something 1" } } }