VBScript array_uintersect_assoc function

A VBScript equivalent of PHP’s array_uintersect_assoc


Function array_uintersect_assoc(mAry1,mAry2,data_compare_func)

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

    If isArray(mAry1) Then

        For key = 0 to uBound(mAry1)

            If array_key_exists(key, mAry2) Then
                execute("found = " & data_compare_func & "(mAry1(key), mAry2(key))")
                If found = 0 Then
                    If output.Exists(key) Then
                        output(key) = mAry1(key)
                    Else
                        output.Add key, mAry1(key)
                    End If
                End If
            End If
        Next

    ElseIf isObject(mAry1) Then

        For Each key In mAry1
            If array_key_exists(key, mAry2) Then
                execute("found = " & data_compare_func & "(mAry1(key), mAry2(key))")
                If found = 0 Then

                    If output.Exists(key) Then
                        output(key) = mAry1(key)
                    Else
                        output.Add key, mAry1(key)
                    End If
                End If
            End If
        Next

    End If

    set array_uintersect_assoc = output

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