[PHP] Delete array element
How can I delete a key and it's value from an array? for example: $test = array(0='yes', 2='no', 5='maybe', 7='so'); And I wanted to delete the second key 2 so I could end up with an array like so: $test = array(0='yes', 5='maybe', 7='so'); How would I go about doing that? Thanks! Rick If I accept you as you are, I will make you worse; however, if I treat you as though you are what you are capable of becoming, I help you become that. - Johann Wolfgang von Goethe -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Delete array element
How can I delete a key and it's value from an array? for example: $test = array(0='yes', 2='no', 5='maybe', 7='so'); And I wanted to delete the second key 2 so I could end up with an array like so: $test = array(0='yes', 5='maybe', 7='so'); unset($test[2]); ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Delete array element
Ok I feel a little sheepish after that answer :) Still not working though due to my variable.. help! unset({$_SESSION[map][mapText][$_POST[Email]]}); Im getting errors on this because I havent figured out how to get it to understand that variable :( Rick If I accept you as you are, I will make you worse; however, if I treat you as though you are what you are capable of becoming, I help you become that. - Johann Wolfgang von Goethe From: John W. Holmes [EMAIL PROTECTED] Organization: U.S. Army Reply-To: [EMAIL PROTECTED] Date: Wed, 11 Dec 2002 21:37:18 -0500 To: 'Richard Baskett' [EMAIL PROTECTED], 'PHP General' [EMAIL PROTECTED] Subject: RE: [PHP] Delete array element How can I delete a key and it's value from an array? for example: $test = array(0='yes', 2='no', 5='maybe', 7='so'); And I wanted to delete the second key 2 so I could end up with an array like so: $test = array(0='yes', 5='maybe', 7='so'); unset($test[2]); ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Delete array element
*sigh* n/m I just got rid of the curly braces and that did the trick. Thanks! Rick Science without religion is lame, religion without science is blind. - Albert Einstein From: Richard Baskett [EMAIL PROTECTED] Date: Wed, 11 Dec 2002 18:50:20 -0800 To: [EMAIL PROTECTED], PHP General [EMAIL PROTECTED] Subject: Re: [PHP] Delete array element Ok I feel a little sheepish after that answer :) Still not working though due to my variable.. help! unset({$_SESSION[map][mapText][$_POST[Email]]}); Im getting errors on this because I havent figured out how to get it to understand that variable :( Rick If I accept you as you are, I will make you worse; however, if I treat you as though you are what you are capable of becoming, I help you become that. - Johann Wolfgang von Goethe From: John W. Holmes [EMAIL PROTECTED] Organization: U.S. Army Reply-To: [EMAIL PROTECTED] Date: Wed, 11 Dec 2002 21:37:18 -0500 To: 'Richard Baskett' [EMAIL PROTECTED], 'PHP General' [EMAIL PROTECTED] Subject: RE: [PHP] Delete array element How can I delete a key and it's value from an array? for example: $test = array(0='yes', 2='no', 5='maybe', 7='so'); And I wanted to delete the second key 2 so I could end up with an array like so: $test = array(0='yes', 5='maybe', 7='so'); unset($test[2]); ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Delete array element
Remove the {braces}, those are only used when inside a {$strin['g']}. Also, be sure to 'quote' your array indices. unset($arr['foo'][$bar]); Regards, Philip Olson On Wed, 11 Dec 2002, Richard Baskett wrote: Ok I feel a little sheepish after that answer :) Still not working though due to my variable.. help! unset({$_SESSION[map][mapText][$_POST[Email]]}); Im getting errors on this because I havent figured out how to get it to understand that variable :( Rick If I accept you as you are, I will make you worse; however, if I treat you as though you are what you are capable of becoming, I help you become that. - Johann Wolfgang von Goethe From: John W. Holmes [EMAIL PROTECTED] Organization: U.S. Army Reply-To: [EMAIL PROTECTED] Date: Wed, 11 Dec 2002 21:37:18 -0500 To: 'Richard Baskett' [EMAIL PROTECTED], 'PHP General' [EMAIL PROTECTED] Subject: RE: [PHP] Delete array element How can I delete a key and it's value from an array? for example: $test = array(0='yes', 2='no', 5='maybe', 7='so'); And I wanted to delete the second key 2 so I could end up with an array like so: $test = array(0='yes', 5='maybe', 7='so'); unset($test[2]); ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php