note 83441 added to function.array-pop
| From: | tom at sirwhite dot com | Date: | Mon, 26 May 2008 17:37:34 +0000 |
| Subject: | note 83441 added to function.array-pop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139798@lists.php.net to get a copy of this message | ||
@Orsi
correct me if I'm wrong... but an easier version might be
<?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)
{
$key = array_search($deleteIt,$array,TRUE);
if($key === FALSE)
return FALSE;
unset($array[$key]);
if(!$useOldKeys)
$array = array_values($array);
return TRUE;
}
?>
--untested but should work.. rite?--
----
Server IP: 117.104.160.194
Probable Submitter: 58.179.151.223
----
Manual Page -- http://www.php.net/manual/en/function.array-pop.php
Edit -- https://master.php.net/note/edit/83441
Del: integrated -- https://master.php.net/note/delete/83441/integrated
Del: useless -- https://master.php.net/note/delete/83441/useless
Del: bad code -- https://master.php.net/note/delete/83441/bad+code
Del: spam -- https://master.php.net/note/delete/83441/spam
Del: non-english -- https://master.php.net/note/delete/83441/non-english
Del: in docs -- https://master.php.net/note/delete/83441/in+docs
Del: other reasons-- https://master.php.net/note/delete/83441
Reject -- https://master.php.net/note/reject/83441
Search -- https://master.php.net/manage/user-notes.php