note 108183 added to ref.array
| From: | topor-grabowski at viversum dot de | Date: | Thu, 05 Apr 2012 09:53:44 +0000 |
| Subject: | note 108183 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-186979@lists.php.net to get a copy of this message | ||
If your searching for a function that is deleting all elements in an array with the same key here is
it.
I was searching for something like that but did not find it.
Hope you will like it and use it.
//deletes all $array entries with $valueToDelete as element value; does function recursive
//without changing original array
public static function array_delete_elements($array = null, $valueToDelete = null) {
//no array given
if (!isset($array)) {
return null;
}
//process
$resultList = array();
foreach ($array as $entryKey => $entryValue) {
if (is_array($entryValue)) {
//entry is array and should be handled again recursive
$resultList[$entryKey] = array_delete_elements($entryValue, $valueToDelete);
} else {
if ($entryValue != $valueToDelete) {
$resultList[$entryKey] = $entryValue;
}
}
}
return $resultList;
}
----
Server IP: 69.147.83.197
Probable Submitter: 195.226.123.90
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit -- https://master.php.net/note/edit/108183
Del: integrated -- https://master.php.net/note/delete/108183/integrated
Del: useless -- https://master.php.net/note/delete/108183/useless
Del: bad code -- https://master.php.net/note/delete/108183/bad+code
Del: spam -- https://master.php.net/note/delete/108183/spam
Del: non-english -- https://master.php.net/note/delete/108183/non-english
Del: in docs -- https://master.php.net/note/delete/108183/in+docs
Del: other reasons-- https://master.php.net/note/delete/108183
Reject -- https://master.php.net/note/reject/108183
Search -- https://master.php.net/manage/user-notes.php