note 108979 added to function.array-search
| From: | lupuswolfram at gmail dot com | Date: | Sat, 09 Jun 2012 12:16:12 +0000 |
| Subject: | note 108979 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-188509@lists.php.net to get a copy of this message | ||
I used this function to delete some values from an array.
If the 3rd parameter is set to false, only the first occurrence is deleted. It outputs a clearly
sorted array.
<?php
function array_delete ($needle, $haystack, $all = true) {
$haystack_updated = $haystack;
foreach ($haystack as $num => $val) {
if ($val == $needle && $all) {
unset ($haystack_updated [$num]);
}
elseif ($val == $needle && $all === false && !isset ($done)) {
$done = true;
unset ($haystack_updated [$num]);
}
}
$haystack_updated = array_values ($haystack_updated);
return $haystack_updated;
}
?>
----
Server IP: 212.124.37.9
Probable Submitter: 88.159.229.137
----
Manual Page -- http://www.php.net/manual/en/function.array-search.php
Edit -- https://master.php.net/note/edit/108979
Del: integrated -- https://master.php.net/note/delete/108979/integrated
Del: useless -- https://master.php.net/note/delete/108979/useless
Del: bad code -- https://master.php.net/note/delete/108979/bad+code
Del: spam -- https://master.php.net/note/delete/108979/spam
Del: non-english -- https://master.php.net/note/delete/108979/non-english
Del: in docs -- https://master.php.net/note/delete/108979/in+docs
Del: other reasons-- https://master.php.net/note/delete/108979
Reject -- https://master.php.net/note/reject/108979
Search -- https://master.php.net/manage/user-notes.php