src/Primitive/Support/Arr.php
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 ((is_array($array) && ( ! isset($array[$key]) || ! is_array($array[$key]))) ||
                (is_object($array) && ( ! isset($array->{$key}) || ! is_array($array->{$key}))))
            {
                if (is_array($array)) $array[$key] = [];
                elseif (is_object($array)) $array->{$key} = [];
            }

            if (is_array($array)) $array =& $array[$key];
            elseif (is_object($array)) $array =& $array->{$key};
        }

        $key = array_shift($keys);

        if (is_array($array)) $array[$key] = $value;
        elseif (is_object($array)) $array->{$key} = $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 ((is_array($array) && ( ! isset($array[$key]) || ! is_array($array[$key]))) ||
                (is_object($array) && ( ! isset($array->{$key}) || ! is_array($array->{$key}))))
            {
                if (is_array($array)) $array[$key] = [];
                elseif (is_object($array)) $array->{$key} = [];
            }

            if (is_array($array)) $array =& $array[$key];
            elseif (is_object($array)) $array =& $array->{$key};
        }

        $key = array_shift($keys);

        if (is_array($array)) $array[$key] = $value;
        elseif (is_object($array)) $array->{$key} = $value;

        return $array;
    }
Set item to a given key using "dot" notation.

If no key is given to the method, the entire array will be replaced.

@param  array|object  $array
@param  string $key
@param  mixed  $value

@return array