VBScript array_unique function

A VBScript equivalent of PHP’s array_unique


Function array_unique(arr)

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

    If isArray(arr) Then
        For key = 0 to uBound(arr)
            found = array_search(arr(key),output,false)
            If found = false and varType(found) = 11 Then
                output.Add key, arr(key)
            End If
        Next
    ElseIf isObject(arr) Then
        For Each key In arr
            found = array_search(arr(key),output,false)
            If found = false and varType(found) = 11 Then
                    output.Add key, arr(key)
            End If
        next
    End If

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