Re: Proper way to remove an element from an array
| From: | tedd | Date: | Wed, 11 Jul 2007 01:22:02 +0000 |
| Subject: | Re: Proper way to remove an element from an array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-258590@lists.php.net to get a copy of this message | ||
At 2:23 PM -0700 7/10/07, Dan wrote:
I know in some languages there's a right way to remove an element from an array and other ways that will give you problems. In PHP can I just set $arrayname[key] = null? Or will I then end up with key => null as a value. I looked on php.net under array functions for a bit and I didn't find any sort of remove element function. I've just never needed to do this before. - DanDan: After after you delete the element, as Robert suggested with unset(), then you can renumber using array_merge() like so: $array = array_merge($array); Here's an example: http://www.webbytedd.com/b/delete-array-element/ Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com