- array_shift: documentation ( source)
- explode: documentation ( source)
<?php
class t {
private static $configs = ["a" => ["b" => "c"]];
public static function set($name, $value)
{
$keyParts = explode(".", $name);
$config =& self::$configs;
while (!empty($keyParts)) {
$key = array_shift($keyParts);
if (!isset($config[$key])) {
$config[$key] = [];
}
if (empty($keyParts)) {
$config[$key] = $value;
return;
}
$tconfig =& $config[$key];
$config = $tconfig;
}
}
}
t::set("a.b", "vittu");