I have an array with configuration tree:
$cfg = array('global' => array(
'project' => 'foo',
'base_url' => '/path/',
'charset' => 'utf-8',
'timezone' => 'Europe/Lisbon',
'environment' => 'development'),
//...
);
I need to insert an element into the tree (or possibly change it) given strings such as "global:project" and "bar" where first specifies a path to an element and second its value. So the value 'foo' in $cfg['global']['project'] would become 'bar'.
Here is the function I need:
function set_cfg($path, $value)
{ /* Alter $cfg with the given settings */ }
So I start by exploding the path string with ':' and have an array with path keys:
$path = explode(':', $path)
What's next? How can I define (recursively?) an operation of keys insertion into the $cfg array?