/**
* Set an array item to a given value using "dot" notation.
*
* If no key is given to the method, the entire array will be replaced.
*
* @param array $array
* @param string $key
* @param mixed $value
* @return array
*/
public static function set(&$array, $key, $value)
{
if (is_null($key)) return $array = $value;
$keys = explode('.', $key);
while (count($keys) > 1)
{
$key = array_shift($keys);
// If the key doesn't exist at this depth, we will just create an empty array
// to hold the next value, allowing us to create the arrays to hold final
// values at the correct depth. Then we'll keep digging into the array.
if ( ! isset($array[$key]) || ! is_array($array[$key]))
{
$array[$key] = array();
}
$array =& $array[$key];//这里吧$array 覆盖到 $array
}
$array[array_shift($keys)] = $value;
return $array;//这里最终返回的成你操作的最后一个层级了,
//不在是原数组了啊,如果你操作的是顶层的不会看到
//这个BUG如果是二次 三层 返回的永远是最后一层啊
}
看我注释中描述的,肿么破?