VBScript array_change_key_case function

A VBScript equivalent of PHP’s array_change_key_case


Const CASE_UPPER = 1
Const CASE_LOWER = 0
Function array_change_key_case(ByRef mObj, flag)

    if flag <> CASE_UPPER and flag <> CASE_LOWER then Exit Function
    if Not isObject(mObj) Then Exit Function

    Dim cnt,i

    arykey = mObj.Keys
    aryval = mObj.Items
    cnt    = mObj.Count -1
    mObj.RemoveAll

    Select Case flag
    Case CASE_UPPER

        For i = 0 to cnt
            mObj.Add Ucase(arykey(i)), aryval(i)
        Next

    Case CASE_LOWER

        For i = 0 to cnt
            mObj.Add Lcase(arykey(i)), aryval(i)
        Next

    End Select

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