170

Possible Duplicate:
How to delete an element from an array in php?

For instance,

Array(      
    [0] => Array
        (
            [0] => hello
            [1] => open
        )

    [1] => Array
        (
            [0] => good
            [1] => center
        )

    [2] => Array
        (
            [0] => hello
            [1] => close
        )
)

I want to delete the element which key is 1, after the operation:

Array(
    [0] => Array
        (
            [0] => hello
            [1] => open
        )

    [2] => Array
        (
            [0] => hello
            [1] => close
        )
)
Community
  • 1
  • 1
Bruce Dou
  • 4,673
  • 10
  • 37
  • 56
  • 5
    The answers for this question seem to answer "How do I delete elements from an array using an _index_ and not a _key_. – Lucas Apr 05 '16 at 18:48
  • @LucasMorgan actually there's no difference, the index is the key for those without an explicit index. – Prajwol Onta Feb 25 '20 at 12:06

3 Answers3

298

PHP

unset($array[1]);
David Kuridža
  • 7,026
  • 5
  • 26
  • 25
33

You don't say what language you're using, but looking at that output, it looks like PHP output (from print_r()).
If so, just use unset():

unset($arr[1]);
Zanshin13
  • 980
  • 4
  • 19
  • 39
cletus
  • 616,129
  • 168
  • 910
  • 942
21

this looks like PHP to me. I'll delete if it's some other language.

Simply unset($arr[1]);

mauris
  • 42,982
  • 15
  • 99
  • 131