note 70034 modified in function.array-unique by levim
| From: | levim@php.net | Date: | Sun, 20 Dec 2015 05:25:05 +0000 |
| Subject: | note 70034 modified in function.array-unique by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-204495@lists.php.net to get a copy of this message | ||
Taking the advantage of array_unique, here is a simple function to check if an array has duplicate
values.
It simply compares the number of elements between the original array and the array_uniqued array.
<?php
function array_has_duplicates(array $array)
{
$uniq = array_unique($array);
return count($uniq) != count($array);
}
?>
--was--
Taking the advantage of array_unique, here is a simple function to check if an array has duplicate
values.
It simply compares the number of elements between the original array and the array_uniqued array.
<?php
function array_search_dups($array)
{
$dup_array = $array;
$dup_array = array_unique($dup_array);
if(count($dup_array) != count($array))
{
return TRUE;
}
else
{
return FALSE;
}
}
?>
http://php.net/manual/en/function.array-unique.php