note 32969 added to ref.array

From: Date: Thu, 12 Jun 2003 11:32:58 +0000
Subject: note 32969 added to ref.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-50223@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/ref.array.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+32969 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+32969&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+32969&report=yes

« previous php.notes (#50223) next »