Hi all,
I am writing an account management system for servers. It has a configuration class with several variables, one is an array with nested variables in it. The problem I am having is the array with the nested variable:
array = array(
"file_storage"=>array("quota"=>"100MB", "types"=>array("bytehoard", "quixplorer", "purftpd")),
"action"=>null,
"class"=>null,
"pureftpd"=>array("database"=>array("username"=>null, "name"=>null, "password"=>null),
"bytehoard"=>array("database"=>array("username"=>null, "name"=>null, "password"=>null),
"mysql_database"=>array("administrator"=>array("username"=>null, "password"=>null), "hostname"=>null, "port=>null));
Okay, I think you guys get the idea. What I want to do is call a function set_configuration($array, $keys, $values) and have it set the value for one of the keys. The value can be an array, and the keys can be an array. For example, if I want to set the mysql administrator username, keys would look like this:
$keys = array("mysql_database", "adminstrator", "username");
While I have a function that can get the value at that key, I don't know how I would go about modifying it. The function I wrote to find the value at the key is as follows.
function get_configuration($array, $key)
{
$temp_array;
$search_key;
if(is_array($key))
$search_key = $key[0];
else
$search_key = $key;
if(is_array($array))
$temp_array = $array[$search_key];
else if($array === null)
$temp_array = $this->settings[$search_key];
else
return($array);
$key_size = count($key);
$new_key;
if(is_array($temp_array) && is_array($key))
{
//If there is more searching to be done, continue, otherwise, give up.
for($j=1;$j<$key_size;++$j)
$new_key[] = $key[$j];
return($this->get_configuration($temp_array, $new_key));
}
else
return($temp_array);
}
Please let me know if you have any ideas about how I can go about doing this. I know I can simplify the structure, but it is more powerful to do it this way since I will be adding much more information that what is up there, and things are treated more as objects. Let me know if there is a simple function that already does this or if I am over looking something.
Thanks,
Walter