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;
    }
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;
    }
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 ; }
Merge array recursively.

@param   array $array1  Array 1 to be merge.
@param   array ...$args Array more to be merge.

@return  array Merged array.
@throws \InvalidArgumentException

@since   4.0
Merge array recursively .