Given an associative array:
array("key1" => "value1", "key2" => "value2", ...)
How would I go about removing a certain key-value pair, given the key?
You can use unset:
unset
unset($array['key-here']);
Example:
$array = array("key1" => "value1", "key2" => "value2"); print_r($array); unset($array['key1']); print_r($array); unset($array['key2']); print_r($array);
Output:
Array ( [key1] => value1 [key2] => value2 ) Array ( [key2] => value2 ) Array ( )
2.1m questions
2.1m answers
60 comments
57.0k users