How to delete an array element based on key?

PhpArrays

Php Problem Overview


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

Php Solutions


Solution 1 - Php

PHP

unset($array[1]);

Solution 2 - Php

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

Solution 3 - Php

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

Simply unset($arr[1]);

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBruce DouView Question on Stackoverflow
Solution 1 - PhpDavid KuridžaView Answer on Stackoverflow
Solution 2 - PhpcletusView Answer on Stackoverflow
Solution 3 - PhpmaurisView Answer on Stackoverflow