array values to nested array with PHP -


i'm trying figure out how can use values indexed array path array. i'm exploding string array, , based on values in array i'm looking value in array.

example:

$haystack['my']['string']['is']['nested'] = 'hello'; $var = 'my@string@is@nested'; $items = explode('@', $var);  // .. echo $haystack[... items..?] 

the number of values may differ, it's not option $haystack[$items[0][$items[1][$items[2][$items[3]].

any suggestions?

you can use loop -

$haystack['my']['string']['is']['nested'] = 'hello'; $var = 'my@string@is@nested'; $items = explode('@', $var);  $temp = $haystack; foreach($items $v) {     $temp = $temp[$v]; // store current array value } echo $temp; 

demo


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -