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']);

 

posted @ 2020-07-09 14:10  Ryan_zheng  阅读(890)  评论(0编辑  收藏  举报