给定一个关联数组:
array("key1" => "value1", "key2" => "value2", ...)
给定键,我将如何删除某个键值对?
您可以使用unset:
unset
unset($array['key-here']);
例子:
$array = array("key1" => "value1", "key2" => "value2"); print_r($array); unset($array['key1']); print_r($array); unset($array['key2']); print_r($array);
输出:
Array ( [key1] => value1 [key2] => value2 ) Array ( [key2] => value2 ) Array ( )