note 17351 added to function.array-slice
| From: | Freediver at NOSPAM dot bellsouth dot net | Date: | Wed, 05 Dec 2001 15:29:26 +0000 |
| Subject: | note 17351 added to function.array-slice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-21638@lists.php.net to get a copy of this message | ||
For array_slice documentation:
Here is a little function that will delete an element from either an index or associative array
(assuming it is one or the other, and that the element only exists once):
function array_delete (&$aArray, $element) {
// Element is key in associative array
if ($aArray[$element] != null) {
$iPos = array_search($element, array_keys($aArray));
array_splice($aArray, $iPos, 1);
}
// Element is value in indexed array
else if (in_array($element, $aArray) == true) {
$iPos = array_search($element, $aArray);
$aBegin = array_slice($aArray, 0, $iPos);
$aEnd = array_slice($aArray, $iPos + 1);
$aArray = array_merge($aBegin, $aEnd);
}
}
--
http://www.php.net/manual/en/function.array-slice.php
http://master.php.net/manage/user-notes.php?action=edit+17351
http://master.php.net/manage/user-notes.php?action=delete+17351
http://master.php.net/manage/user-notes.php?action=reject+17351