Deleting an element from an array in PHP

后端 未结 30 3350
时光说笑
时光说笑 2020-11-21 05:55

Is there an easy way to delete an element from an array using PHP, such that foreach ($array) no longer includes that element?

I thought that setting it

30条回答
  •  悲哀的现实
    2020-11-21 06:33

    To avoid doing a search one can play around with array_diff:

    $array = array(3, 9, 11, 20);
    $array = array_diff($array, array(11) ); // removes 11
    

    In this case one doesn't have to search/use the key.

提交回复
热议问题