note 28892 added to function.array-unique
| From: | martin at lucas-smith dot co dot uk | Date: | Mon, 27 Jan 2003 11:12:15 +0000 |
| Subject: | note 28892 added to function.array-unique | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-42809@lists.php.net to get a copy of this message | ||
To get a list of the duplicated values in an array, array_unique isn't much help. Instead, use
array_filter in conjunction with a callback function, as below:
$checkKeysUniqueComparison = create_function('$value','if ($value > 1) return
true;');
$result = array_keys (array_filter (array_count_values($array), $checkKeysUniqueComparison));
These two lines therefore will create $result, an array of duplicated values in the array $array,
once each. E.g. the array
$array = array ("a", "b", "a", "b", "x",
"y", "z", "x");
gives the result
Array([0] => a [1] => b [2] => x)
--
http://www.php.net/manual/en/function.array-unique.php
http://master.php.net/manage/user-notes.php?action=edit+28892
http://master.php.net/manage/user-notes.php?action=delete+28892
http://master.php.net/manage/user-notes.php?action=reject+28892