note 80327 added to function.array-pop

From: Date: Thu, 10 Jan 2008 15:05:27 +0000
Subject: note 80327 added to function.array-pop
Groups: php.notes 
Request: Send a blank email to php-notes+get-134995@lists.php.net to get a copy of this message
Hi, Here is a simple function which delete one element from the array (with value): <?php /* * This function deletes the given element from a one-dimension array * Parameters: $array: the array (in/out) * $deleteIt: the value which we would like to delete * $useOldKeys: if it is false then the function will re-index the array (from 0, 1, ...) * if it is true: the function will keep the old keys * Returns true, if this value was in the array, otherwise false (in this case the array is same as before) */ function deleteFromArray(&$array, $deleteIt, $useOldKeys = FALSE) { $tmpArray = array(); $found = FALSE; foreach($array as $key => $value) { if($value !== $deleteIt) { if(FALSE === $useOldKeys) { $tmpArray[] = $value; } else { $tmpArray[$key] = $value; } } else { $found = TRUE; } } $array = $tmpArray; return $found; } ?> Maybe it will help somebody... ---- Server IP: 80.81.171.181 Probable Submitter: 192.100.124.218 ---- Manual Page -- http://www.php.net/manual/en/function.array-pop.php Edit -- https://master.php.net/note/edit/80327 Del: integrated -- https://master.php.net/note/delete/80327/integrated Del: useless -- https://master.php.net/note/delete/80327/useless Del: bad code -- https://master.php.net/note/delete/80327/bad+code Del: spam -- https://master.php.net/note/delete/80327/spam Del: non-english -- https://master.php.net/note/delete/80327/non-english Del: in docs -- https://master.php.net/note/delete/80327/in+docs Del: other reasons-- https://master.php.net/note/delete/80327 Reject -- https://master.php.net/note/reject/80327 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#134995) next »