Deleting an element from an array in PHP

后端 未结 30 3280
时光说笑
时光说笑 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:24

    Use array_search to get the key and remove it with unset if found:

    if (($key = array_search('word', $array)) !== false) {
        unset($array[$key]);
    }
    

提交回复
热议问题