I have an array with a 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), such lines as "global:project"and "bar"where the path to the element and its second value are set first. Thus, the value 'foo'in $cfg['global']['project']becomes 'bar'.
Here is the function I need:
function set_cfg($path, $value)
{ }
So, I start by exploding the path string with ':'and has an array with path keys:
$path = explode(':', $path)
What's next? How can I define (recursively?) The operation of inserting keys into an array $cfg?
source
share