3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function getValue($testArray, $exploded, $index) { if(is_array($testArray[$exploded[$index]])) { return getValue($testArray[$exploded[$index]], $exploded, $index++); } else { return $testArray[$exploded[$index]]; } } $string = 'router.format'; $testArray = array( 'router' => array( 'format' => 'xml', ), ); $exploded = explode(".", $string); /*if(count($exploded) != count($testArray)) { throw new Exception("mismatch"); }*/ $desiredValue = getValue($testArray, $exploded, 0); print_r($desiredValue);
based on 9fm7G
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Notice: Undefined index: router in /in/1Jm14 on line 5 Notice: Undefined index: router in /in/1Jm14 on line 11
Output for 4.3.0 - 5.2.17
Notice: Undefined index: router in /in/1Jm14 on line 5 Notice: Undefined index: router in /in/1Jm14 on line 11