VBScript array_walk function

A VBScript equivalent of PHP’s array_walk


Function array_walk(ByRef arr, callback, userdata)

    Dim key

    If Len( callback ) = 0 Then Exit Function

    If isArray( arr ) Then

        For key = 0 to uBound( arr )
            execute("call " & callback & "(arr(key),key,userdata)")
        Next

    ElseIf isObject( arr ) Then

        Dim return_val

        For Each key In arr
            execute("call " & callback & "(arr.Item(key),key,userdata)")
        Next

    End If

    array_walk = true

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