VBScript array_intersect_key function

A VBScript equivalent of PHP’s array_intersect_key

Function array_intersect_key(mAry1,mAry2)

    Dim result : set result = Server.CreateObject("Scripting.Dictionary")
    Dim result_keys,key
    ReDim arg_keys(1)

    arg_keys(0) = array_keys(mAry1,",false)
    arg_keys(1) = array_keys(mAry2,",false)
    set result_keys = array_intersect(arg_keys(0),arg_keys(1))

    For Each key In result_keys
        result.Add result_keys(key) ,mAry1(result_keys(key))
    set array_intersect_key = result

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