Forum Moderators: coopster

Message Too Old, No Replies

Remove key from associative array

         

sned

12:24 am on Dec 1, 2006 (gmt 0)

10+ Year Member



I have an array that looks something like this:

array(
a=>123,
b=>456,
c=>789,
d=>123
);

I want to remove a key=>value, so the finished array looks like this:

array(
a=>123,
c=>789,
d=>123
);

I'm not sure how to do this, unset just removes the value, not the key. Any suggestions?

Thanks,
-sned

Psychopsia

2:18 am on Dec 1, 2006 (gmt 0)

10+ Year Member



$a = array(
'a' => 123,
'b' => 456,
'c' => 789,
'd' => 123
);

unset($a['b']);
print_r($a);

Hope this helps!

mcavic

2:23 am on Dec 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You beat me to it. The single quotes are probably needed.

Psychopsia

4:50 am on Dec 1, 2006 (gmt 0)

10+ Year Member



Also check out the Array manual [php.net], specially "Array do's and don'ts" section.