PHP Remove elements from associative array

后端 未结 9 1326
一整个雨季
一整个雨季 2020-12-01 06:09

I have an PHP array that looks something like this:

Index              Key     Value
[0]                1       Awaiting for Confirmation
[1]                        


        
相关标签:
9条回答
  • 2020-12-01 06:37

    for single array Item use reset($item)

    0 讨论(0)
  • 2020-12-01 06:40

    Try this:

    $keys = array_keys($array, "Completed");
    

    /edit As mentioned by JohnP, this method only works for non-nested arrays.

    0 讨论(0)
  • 2020-12-01 06:44
    $key = array_search("Mark As Spam", $array);
    unset($array[$key]);
    

    For 2D arrays...

    $remove = array("Mark As Spam", "Completed");
    foreach($arrays as $array){
        foreach($array as $key => $value){
            if(in_array($value, $remove)) unset($array[$key]);
        }
    }
    
    0 讨论(0)
提交回复
热议问题