VBScript array_sum function

A VBScript equivalent of PHP’s array_sum


Function array_sum(mAry)

    array_sum = 0
    If Not isArray(mAry) and Not isObject(mAry) Then Exit Function

    Dim key
    If isObject(mAry) Then
        For Each key in mAry
            array_sum = array_sum + mAry(key)
        Next
    Else
        For Each key in mAry
            array_sum = array_sum + key
        Next
    End If

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