PHP 删除数组指定元素
根据值删除数组元素
<?php $fields = [1, 2, 3, 4, 5]; $key = array_search('4', $fields); unset($fields[$key]);
关联数组根据 key 删除数组元素
<?php $fields = ['key1' => 1, 'key2' => 2, 'key3' => 3]; unset($fields['key2']);
根据值删除数组元素
<?php $fields = [1, 2, 3, 4, 5]; $key = array_search('4', $fields); unset($fields[$key]);
关联数组根据 key 删除数组元素
<?php $fields = ['key1' => 1, 'key2' => 2, 'key3' => 3]; unset($fields['key2']);