Use the following piece of code if you want to insert a value into an array at a path that is extracted from a string.
Example:
You have a syntax like 'a|b|c|d' which represents the array structure, and you want to insert a value X into the array at the position $array['a']['b']['c']['d'] = X.
<?
function array_path_insert(&$array, $path, $value)
{
$path_el = split('\|', $path);
$arr_ref =& $array;
for($i = 0; $i < sizeof($path_el); $i++)
{
$arr_ref =& $arr_ref[$path_el[$i]];
}
$arr_ref = $value;
}
$array['a']['b']['f'] = 4;
$path = 'a|b|d|e';
$value = 'hallo';
array_path_insert($array, $path, $value);
?>
Rock on
Philipp