- print_r: documentation ( source)
- explode: documentation ( source)
<?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);