2013-04-29 30 views
0

是否有一個ASP Classic相當於PHP unset(array1[3])函數?如何取消ASP經典中的數組元素?

+0

這將幫助我們這些誰不知道PHP來形容一下'unset'功能是應該做的。 – 2013-04-29 06:26:03

+0

爲什麼使用它?在ASP中,我們通常在分割數組時使用不同的變量名稱,因此不需要重新組合。 – WilliamK 2013-04-29 07:02:49

+0

PHP中的Unset()會銷燬給定的變量/數組元素。對於我的情況,我需要刪除數組中間的元素。 – reformed 2013-04-30 00:43:47

回答

3

我想這會做到這一點,對於一個數值數組,至少:

sub unset(array, index) 
    if index < lbound(array) or index > ubound(array) then exit sub 

    dim i, move 
    move = false 
    for i = lbound(array) to ubound(array) 
     if i = index then move = true 

     if move and i < ubound(array) then 
     array(i) = array(i + 1) 
     end if 
    next 

    redim preserve array(i - 2) 
end sub