note 28810 added to function.array-merge
| From: | jasonNOSPAM at tekscodeNOSPAM dot com | Date: | Fri, 24 Jan 2003 16:02:23 +0000 |
| Subject: | note 28810 added to function.array-merge | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-42695@lists.php.net to get a copy of this message | ||
I have an array with numeric keys and numeric values, and I wanted to condense the array such that
if a value exists more than once, it's just taken out. For example, array(1, 3, 5, 10, 5)
would condense down to array(1, 3, 5, 10). I don't see a function that behaves exactly like
this, but I've been using this function to do it:
function array_condense_values($input) {
if (!is_array($input)) return (false);
$diet_array = array();
foreach ($input as $item) {
if (!in_array($item, $diet_array)) {
$diet_array[] = $item;
}
}
return ($diet_array);
}
--
http://www.php.net/manual/en/function.array-merge.php
http://master.php.net/manage/user-notes.php?action=edit+28810
http://master.php.net/manage/user-notes.php?action=delete+28810
http://master.php.net/manage/user-notes.php?action=reject+28810