开发者

How to delete an array element based on key? [duplicate]

开发者 https://www.devze.com 2022-12-10 08:58 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: How to delete an element from an array in php?
This question already has answers here: Closed 11 years ago.

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
      开发者_Python百科  )

    [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
        )
)


PHP

unset($array[1]);


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


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

Simply unset($arr[1]);

0

精彩评论

暂无评论...
验证码 换一张
取 消