Possible Duplicate:
String with array structure to Array
I have a string "db/yum/user", and I'm trying to explode it so each element of / becomes a deeper dimension.
So the direct method of creating the data variable would be
$config['db']['yum']['user'] = "val";
My attempt so far:
$config = array();
function set_config($key,$value){
global $config;
//Multi deminsional config
$multi_configs = explode('/',$key);
if($multi_configs!==false){
$build_up = array();
$c =& $build_up;
foreach($multi_configs as $multi_config){
$c[$multi_config] = array();
$c =& $c[$multi_config];
}
//$c = $value;
array_merge($config,$c);
return;
}
$config[$key] = $value;
}
set_config('db/yum/user','val');
set_config('db/yum/server','val2');
//etc,etc,etc, this was modified to make more sense in this context.