public static function mergeRecursive($array1)
    {
        $result = $array1;

        $args = func_get_args();
        array_shift($args);

        foreach ($args as $i => $array) {
            if (!is_array($array)) {
                throw new \InvalidArgumentException(sprintf('Argument #%d is not an array.', $i + 2));
            }

            foreach ($array as $key => &$value) {
                if (is_array($value) && isset($result[$key]) && is_array($result[$key])) {
                    $result[$key] = static::mergeRecursive($result [$key], $value);
                } else {
                    $result[$key] = $value;
                }
            }
        }

        return $result;
    }