mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-03 14:10:57 +08:00
improve arr_set()
This commit is contained in:
@@ -233,7 +233,7 @@ function config($key, $default = null)
|
|||||||
* @param null $name
|
* @param null $name
|
||||||
* @return array|mixed|string
|
* @return array|mixed|string
|
||||||
*/
|
*/
|
||||||
function get_setting($name = null)
|
function get_setting($name = null, $prefix = null)
|
||||||
{
|
{
|
||||||
static $settings;
|
static $settings;
|
||||||
if (is_null($settings)) {
|
if (is_null($settings)) {
|
||||||
@@ -342,15 +342,21 @@ function arr_get($array, $key, $default = null)
|
|||||||
|
|
||||||
function arr_set(&$array, $key, $value)
|
function arr_set(&$array, $key, $value)
|
||||||
{
|
{
|
||||||
if (strpos($key, '.') === false) {
|
$parts = explode('.', $key);
|
||||||
$array[$key] = $value;
|
$last = null;
|
||||||
}
|
while (true) {
|
||||||
foreach (explode('.', $key) as $segment) {
|
$segment = array_pop($parts);
|
||||||
if (isset($array[$segment])) {
|
if (empty($segment)) {
|
||||||
$array = $array[$segment];
|
return $array;
|
||||||
} else {
|
}
|
||||||
return $default;
|
if (is_null($last)) {
|
||||||
}
|
$array[$segment] = $value;
|
||||||
}
|
} else {
|
||||||
return $array;
|
$array[$segment] = $array;
|
||||||
|
unset($array[$last]);
|
||||||
|
}
|
||||||
|
$last = $segment;
|
||||||
|
|
||||||
|
}
|
||||||
|
return $array;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user