VBScript array_intersect_ukey function

A VBScript equivalent of PHP’s array_intersect_ukey


Function array_intersect_ukey(mAry1,mAry2,key_compare_func)

    Dim result : set result = Server.CreateObject("Scripting.Dictionary")
    Dim key,k,compare

    If isArray(mAry1) Then
        For key = 0 to uBound(mAry1)

            If isArray(mAry2) Then
                For k = 0 to uBound(mAry2)
                    execute("compare = " & key_compare_func & "(key,k)")
                    If compare = 0 Then
                        result.Add key, mARy1(key)
                        Exit For
                    End If
                Next
            ElseIf isObject(mAry2) Then
                For Each k In mAry2
                    execute("compare = " & key_compare_func & "(key,k)")
                    If compare = 0 Then
                        result.Add key, mARy1(key)
                        Exit For
                    End If
                Next
            End If

        Next
    ElseIf isObject(mAry1) Then
        For Each key In mAry1

            If isArray(mAry2) Then
                For k = 0 to uBound(mAry2)
                    execute("compare = " & key_compare_func & "(key,k)")
                    If compare = 0 Then
                        result.Add key, mARy1(key)
                        Exit For
                    End If
                Next
            ElseIf isObject(mAry2) Then
                For Each k In mAry2
                    execute("compare = " & key_compare_func & "(key,k)")
                    If compare = 0 Then
                        result.Add key, mARy1(key)
                        Exit For
                    End If
                Next
            End If

        Next
    End If

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