📅  最后修改于: 2022-03-11 14:53:57.750000             🧑  作者: Mango
class Arr
{
public static function setValue(&$data, $path, $value)
{
$temp = &$data;
foreach ($path as $key) $temp = &$temp[$key];
$temp = $value;
return $value;
}
public static function getValue(&$data, $path, $value)
{
$temp = &$data;
foreach ($path as $key) $temp = &$temp[$key];
return $temp;
}
public static function incValue(&$data, $path, $value)
{
$temp = (int)self::getValue($data, $path, $value)+$value;
self::setValue($data, $path, $temp);
}
}
$d=array();
Arr::incValue($d,array("the","next","value"),10);
echo ''.json_encode($d, JSON_PRETTY_PRINT);
/*
{
"the": {
"next": {
"value": 10
}
}
}
*/