If I have an array that matches successively recursive keys in another array, what is the best way to assign a value to this "path" (if you want to name it)?
For instance:
$some_array = array();
$path = array('a','b','c');
set_value($some_array,$path,'some value');
Now $some_arraymust equal
array(
'a' => array(
'b' => array(
'c' => 'some value'
)))
I am currently using the following:
function set_value(&$dest,$path,$value) {
$addr = "\$dest['" . implode("']['", $path) . "']";
eval("$addr = \$value;");
}
Obviously, this is a very naive approach and poses a security risk, so how would you do it?
source
share