Commit b2991dd6 authored by Taylor Otwell's avatar Taylor Otwell

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

parent 732a1e4a
...@@ -46,21 +46,21 @@ class Arr { ...@@ -46,21 +46,21 @@ class Arr {
*/ */
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;
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment