note 86191 deleted from function.array-slice by danbrown
| From: | danbrown@php.net | Date: | Tue, 07 Oct 2008 14:33:52 +0000 |
| Subject: | note 86191 deleted from function.array-slice by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145128@lists.php.net to get a copy of this message | ||
Note Submitter: businesscatalyst.com
Reason: bad code
----
I tried the arem function provided below and found that when the keys are numeric, a slight
modification needs to be made to keep the returned array indices continuous. Here's my update:
#Remove an element from an array and return the result
function arem($array,$value){
$holding=array();
foreach($array as $k => $v){
if($value!==$v){ //when comparing strings, !== is appropriate here instead of !=
$holding[]=$v; //removed the key so continuous indexes are preserved. Put $k back in if
the keys need to be preserved.
}
}
return $holding;
}