Is there a PHP function to remove any/all key/value pairs that have a certain value from an array?

前端 未结 5 2002
予麋鹿
予麋鹿 2021-01-26 11:27

I think questions like this are the reason why I don\'t like working with PHP. The manual is good, if you can find what you are looking for. After reading through the Array Func

5条回答
  •  逝去的感伤
    2021-01-26 11:45

    Just to add to this...

    array_diff appears to show elements in the first array which don't appear in the second array. It doesn't show those elements which only appear in one or the other array.

    e.g.

     "green", "red", "bicycle", "red");
    $array2 = array("b" => "green", "yellow", "red", "blue", "yellow", "pink");
    $result = array_diff($array1, $array2);
    print_r ($result);
    ?> 
    

    returns

    Array
    (
        [1] => bicycle
    )
    

提交回复
热议问题