note 36713 added to ref.array
| From: | lsimon at commoner dot com | Date: | Mon, 20 Oct 2003 06:38:53 +0000 |
| Subject: | note 36713 added to ref.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-58909@lists.php.net to get a copy of this message | ||
Here are two functions I use alot with arrays and I think come in handy:
//THIS ONE DOESN'T DESTROY THE KEYS OF AN ASSOCIATIVE ARRAY
function array_remove($key, &$array) {
$array_orig = $array;
$array = array();
foreach (array_keys($array_orig) as $keyo) {
if ($keyo != $key) {
$array[$keyo] = $array_orig[$keyo];
}
}
}
//ARRAY VALUE REMOVE - destroys key/val
function array_value_remove($value,&$array) {
if (in_array($value,$array)) {
for ($i=0; $i < count($array); $i++) {
if ($value == $array[$i]) {
array_splice($array, $i, 1);
}
}
}
}
----
Manual Page -- http://www.php.net/manual/en/ref.array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+36713
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36713&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36713&report=yes
Search -- http://master.php.net/manage/user-notes.php