I have a given path with keys (in a separate array) to a subarray within a multidimensional one.
$path_array = array( 'first', 'new', 'best');
$multi_data = array(
'first' => array(
'example' => 'good',
'other' => 'well',
'new' => array(
'subset' => 'none',
'best' => 'stackoverflow',
)
)
);
The arrays are changing of course due to dynamically generated data.
My Question: How to get the correct value or array by the path that i have got? A correct static approach would be:
echo $multi_data['first']['new']['best'];
// prints: stackoverflow
I tried foreach-Loop on $path_array, but i cant put the path elements together (keys is square brackets).
$multi_data? Is$path_arrayconstant or will be changing as well? And is the order in$path_arraythe order you need to search?$path_arraystand for every indentation level. On each indentation every key is unique. But duplicates on different indentations can occur.$path_arraywill change, too because its generated dynamically.$path_arrayis alsonand not fixed right? Just a thought, having a path in an array might not be the most efficient way, you should use a linked list.