i want edit a value of key like $class->set("this.is.a.children.key", "and this is my value")
.
My function:
public function set ($key, $value) {
if (array_key_exists($key, $this->config)) {
$this->config[$key] = $value;
return true;
} else {
if(strpos($key, ".")){
$keys = explode(".", $key);
if (count($keys) > 0) {
if (array_key_exists($keys[0], $this->config)) {
function rv($source, $array_keys, $value){
if (count($array_keys) == 1) {
$source[$array_keys[0]] = $value;
} else {
return rv(
$source[$array_keys[0]],
array_slice($array_keys, 1),
$value
);
}
}
$this->config = rv($this->config, $keys, $value);
}
}
}
}
return false;
}
My Array:
$this->config = array(
"a"=>array(
"b"=>1,
"c"=>array(
"d"=>array(
"e"=>2,
"f"=>"x",
"g"=>null,
)
),
"h"=>null,
"i"=>102.2,
"j"=>array(
3=>3
)
),
"k"=>":)"
);
And my sentence:
$this->set("k", "This is K");
$this->set("a.c.d.g", "This is a -> c -> d -> g");