tags:

views:

64

answers:

3

if i have an array like

array("key1" => "value1", "key2" => "value2", ...)

how would i go about removing a certain key-value pair, given the key? thanks!

+8  A: 

You can use the 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
(
)
Sarfraz
+1 for being the quickest typist.
nickf
Wow... I like that the easy PHP questions take less than 1 minute to be answered.
Cristian
you all deserve this green checkmark =) i can't believe i didn't know that...
gsquare567
+2  A: 

Use unset():

unset($array['key1']);
cletus
+1 for the documentation link
Mithun P
+1  A: 

Using the unset function:

unset($array['key1'])
Cristian