3v4l.org

run code in 300+ PHP versions simultaneously
<?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);

preferences:
43.44 ms | 402 KiB | 5 Q