How to delete an array element based on key?


Question

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
        )
)
1
131
5/23/2017 11:47:24 AM

Accepted Answer

PHP

unset($array[1]);
252
11/4/2009 7:22:34 AM

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]);

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon