VBScript array_udiff_uassoc function

A VBScript equivalent of PHP’s array_udiff_uassoc


Function array_udiff_uassoc(ByVal mAry1,ByVal mAry2, data_compare_func,key_compare_func)

    Dim arr_dif
    set arr_dif = Server.CreateObject("Scripting.Dictionary")

    If Not isObject(mAry1) or Not isObject(mAry2) Then
        set array_diff_assoc = arr_dif : Exit Function
    End If

    Dim j,k,key_result,data_result,found
    For Each j in mAry1

        found = false
        For Each k In mAry2
            execute("key_result  = " & key_compare_func & "(j,k)")
            execute("data_result = " & data_compare_func & "(mAry1(j),mAry2(k))")

            If key_result = 0 and data_result = 0 Then
                found = true
                Exit For
            End If
        Next

        If Not found Then
             arr_dif.Add j , mAry1(j)
        End If
    Next

    set array_udiff_uassoc = 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