VBScript array_shift function

A VBScript equivalent of PHP’s array_shift


Function array_shift(ByRef ary)

    If Not isArray(ary) and Not isObject(ary) then
        array_shift = null
        Exit Function
    End If

    Dim i,key : i = 0

    If isArray(ary) Then
        array_shift = ary(0)

        For i = 0 to uBound(ary)-1
            ary(i) = ary(i+1)
        Next
        Redim Preserve ary(UBound(ary) - 1)

    ElseIf isObject(ary) Then
        For Each key In ary
            array_shift = ary(key)
            ary.Remove(key)
            Exit For
        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