This question already has an answer here:
I have a multi dimensional array in PHP
$somearray = array(
'item1' => array(
'subitem1' => 'Some value',
'subitem2' => 'Some other value',
'subitem3' => array(
'subsubitem' => 'A sub value'
)
),
'item2' => 'a different value'
);
I then have a string map which represents which value I want to select:
"item1/subitem3/subsubitem"
How can I convert from that string map of an array, into:
$wanted_value = $somearray['item1']['subitem3']['subsubitem'];
but keeping in mind the array could be any number of levels deep.
explode
your path, then traverse the array with a recursive function. – mario Nov 21 '13 at 20:23eval('$wanted_value = $somearray["' . str_replace("/",'"]["',$map) . '"];');
Done! But seriously, use @TobSpr's method. =) – jszobody Nov 21 '13 at 20:34