From b2991dd6ba948f9869063507f92b51c9fd662c56 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 15 Aug 2011 10:36:24 -0500 Subject: [PATCH] Fix bug in Arr::set that did not correctly create new array levels. --- system/arr.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/system/arr.php b/system/arr.php index 06889cf2..8532e9eb 100644 --- a/system/arr.php +++ b/system/arr.php @@ -46,21 +46,21 @@ public static function get($array, $key, $default = null) */ public static function set(&$array, $key, $value) { - $reference =& $array; + $keys = explode('.', $key); - foreach (explode('.', $key) as $segment) + while (count($keys) > 1) { - if ( ! isset($reference[$segment])) + $key = array_shift($keys); + + if ( ! isset($array[$key])) { - $reference[$segment] = $value; - - return; + $array[$key] = array(); } - $reference =& $reference[$segment]; + $array =& $array[$key]; } - $reference = $value; + $array[array_shift($keys)] = $value; } } \ No newline at end of file