VBScript array_flip function

A VBScript equivalent of PHP’s array_flip


Function array_flip(trans)

    Dim aryObj : set aryObj = Server.CreateObject("Scripting.Dictionary")

    If Not isArray(trans) and Not isObject(trans) Then
        set array_flip = aryObj
        Exit Function
    End If


    If isArray(trans) Then

        Dim i
        For i = 0 to uBound(trans)
            aryObj( trans(i) ) = i
        Next

    Elseif isObject(trans) Then

        Dim j
        For Each j In trans
            aryObj( trans(j) ) = j
        Next

    End If

    set array_flip = aryObj
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