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)
{
$reference =& $array;
$keys = explode('.', $key);
foreach (explode('.', $key) as $segment)
while (count($keys) > 1)
{
if ( ! isset($reference[$segment]))
{
$reference[$segment] = $value;
$key = array_shift($keys);
return;
if ( ! isset($array[$key]))
{
$array[$key] = array();
}
$reference =& $reference[$segment];
$array =& $array[$key];
}
$reference = $value;
$array[array_shift($keys)] = $value;
}
}