public static function arrayMergeRecursiveUnique($array1, $array2)
    {
        if (empty($array1)) {
            // Optimize the base case
            return $array2;
        }

        foreach ($array2 as $key => $value) {
            if (is_array($value) && isset($array1[$key]) && is_array($array1[$key])) {
                $value = static::arrayMergeRecursiveUnique($array1[$key], $value);
            }
            $array1[$key] = $value;
        }

        return $array1;
    }
public static function arrayMergeRecursiveUnique($array1, $array2)
    {
        if (empty($array1)) {
            // Optimize the base case
            return $array2;
        }

        foreach ($array2 as $key => $value) {
            if (is_array($value) && isset($array1[$key]) && is_array($array1[$key])) {
                $value = static::arrayMergeRecursiveUnique($array1[$key], $value);
            }
            $array1[$key] = $value;
        }

        return $array1;
    }
public static function arrayMergeRecursiveUnique ( $ array1 , $ array2 ) { if ( empty ( $ array1 ) ) { // Optimize the base case return $ array2 ; } foreach ( $ array2 as $ key => $ value ) { if ( is_array ( $ value ) && isset ( $ array1 [ $ key ] ) && is_array ( $ array1 [ $ key ] ) ) { $ value = static :: arrayMergeRecursiveUnique ( $ array1 [ $ key ] , $ value ) ; } $ array1 [ $ key ] = $ value ; } return $ array1 ; }
Recursive Merge with uniqueness

@param array $array1
@param array $array2
@return array
Recursive Merge with uniqueness