VBScript array_diff_key function

A VBScript equivalent of PHP’s array_diff_key


Function array_diff_key(ByVal mAry1,ByVal mAry2)

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

    If Not isObject(mAry1) then
        set array_diff_uassoc = arr_dif
        Exit Function
    End If

    Dim key
    For Each key In mAry1
        arr_dif.Add key, mAry1(key)
    Next

    If isObject(mAry2) Then
        For Each key In mAry2
            If arr_dif.Exists( key ) Then arr_dif.Remove key
        Next
    End If

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