PHP array delete by value (not key)

前端 未结 19 2005
花落未央
花落未央 2020-11-22 15:58

I have a PHP array as follows:

$messages = [312, 401, 1599, 3, ...];

I want to delete the element containing the value $del_val

19条回答
  •  长发绾君心
    2020-11-22 16:16

    The Best way is array_splice

    array_splice($array, array_search(58, $array ), 1);
    

    Reason for Best is here at http://www.programmerinterview.com/index.php/php-questions/how-to-delete-an-element-from-an-array-in-php/

提交回复
热议问题