VBScript array_remove function

A VBScript equivalent of PHP’s array_remove


Function array_remove(mAry,num)

    if Not isArray(mAry) Then Exit Function
    If Not isNumeric(num) Then Exit Function

    Dim strCount
    strCount = uBound(mAry)
    If strCount+1 < num Then
        array_remove = mAry
        Exit Function
    End If

    If (strCount+1) = num Then
        ReDim Preserve mAry(strCount - 1)
        array_remove = mAry
        Exit Function
    End If

    If num = 0 Then
        call array_shift(mAry)
        array_remove = mAry
        Exit Function
    End If

    Dim tmpAry,retAry
    tmpAry = array_chunk(mAry,num)
    call array_shift( tmpAry(1) )

    call array_push(tmpAry(0),tmpAry(1))
    retAry = tmpAry(0)

    if uBound(tmpAry) > 1 Then

        Dim intCounter
        For intCounter = 2 to uBound(tmpAry)
            call array_push(retAry,tmpAry(intCounter))
        Next

    end if

    array_remove = retAry

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