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 ( )
1.4m articles
1.4m replys
5 comments
57.0k users