note 32969 deleted from ref.array by didou
| From: | didou@php.net | Date: | Thu, 12 Jun 2003 14:59:57 +0000 |
| Subject: | note 32969 deleted from ref.array by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-50233@lists.php.net to get a copy of this message | ||
Note Submitter: ng4rrjanbiah@rediffmail.com
----
If you want to remove a particular element from the array without loosing the keys, you can use the
following function:
function RemoveArrayElement($arr, $element)
{
if (($key=array_search($element, $arr))!==false)
unset($arr[$key]);
return( $arr );
}/*---------RemoveArrayElement()----------*/
Example:
$arr =
array("a","b","c","f","x","d","e","z","l");
print_r($arr); //debug
$arr = RemoveArrayElement($arr, "a");
print_r($arr); //removes the "a"
$arr = RemoveArrayElement($arr, "xxx");
print_r($arr); //no match of "xxx"; so displays the original array
HTH,
R. Rajesh Jeba Anbiah