0

Is there an ASP Classic equivalent to PHP unset(array1[3]) function?

reformed
  • 4,505
  • 11
  • 62
  • 88
  • It would help those of us who don't know PHP to describe what the `unset` function is supposed to do. – Cheran Shunmugavel Apr 29 '13 at 06:26
  • Why use it? In ASP we usuallly use a different variable name for the array once it is split, so there is no need to unarray. – WilliamK Apr 29 '13 at 07:02
  • Unset() in PHP destroys a given variable/array element. For my case, I need to delete an element in the middle of an array. – reformed Apr 30 '13 at 00:43

1 Answers1

3

I suppose this will do it, for a numerical array, at least:

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
reformed
  • 4,505
  • 11
  • 62
  • 88