note 36713 deleted from ref.array by pollita
| From: | pollita@php.net | Date: | Thu, 20 Nov 2003 23:23:27 +0000 |
| Subject: | note 36713 deleted from ref.array by pollita | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-60729@lists.php.net to get a copy of this message | ||
Note Submitter: lsimon@commoner.com
----
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);
}
}
}
}