Fix bug in Arr::set that did not correctly create new array levels.

This commit is contained in:
Taylor Otwell 2011-08-15 10:36:24 -05:00
parent 732a1e4a04
commit b2991dd6ba
1 changed files with 8 additions and 8 deletions

View File

@ -46,21 +46,21 @@ public static function get($array, $key, $default = null)
*/ */
public static function set(&$array, $key, $value) 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; $array[$key] = array();
return;
} }
$reference =& $reference[$segment]; $array =& $array[$key];
} }
$reference = $value; $array[array_shift($keys)] = $value;
} }
} }