VBScript array_count_values function

A VBScript equivalent of PHP’s array_count_values


Function array_count_values(mAry)

    Dim obj
    set obj = Server.CreateObject("Scripting.Dictionary")
    if Not isArray(mAry) and Not isObject(mAry) Then
        Set array_count_values = obj
        Exit Function
    End If

    Dim j,k
    Dim intCounter


    For Each j In mAry

        intCounter = 0

        For Each k In mAry
            If j = k Then intCounter = intCounter + 1
        Next

        If Not obj.Exists(j) Then obj.Add j, intCounter

    Next

    Set array_count_values = obj

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