VBScript array_diff function

A VBScript equivalent of PHP’s array_diff

Function array_diff(ByVal mAry1,ByVal mAry2)

    Dim arr_dif,key_c,key,found
    set arr_dif = Server.CreateObject("Scripting.Dictionary")

    If isArray(mAry1) Then
        set mAry1 = array2Dic(mAry1)
    End If

    If isArray(mAry2) Then
        set mAry2 = array2Dic(mAry2)
    End If

    For Each key In mAry1

        found = false
        For Each key_c In mAry2
            If mAry1(key) = mAry2(key_c) Then
                found = true
                Exit For
            End If

        If Not found Then
            arr_dif.add key, mAry1(key)
        End If

    set array_diff = arr_dif

End Function

Please also note that php.vbs offers community built functions and goes by the McDonald’s Theory. We’ll put online functions that are far from perfect, in the hopes to spark better contributions. Do you have one? Then please just:

Other PHP functions in the array extension