note 70034 modified in function.array-unique by danbrown
| From: | danbrown@php.net | Date: | Thu, 06 Nov 2008 14:58:38 +0000 |
| Subject: | note 70034 modified in function.array-unique by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-146222@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_search_dups($array)
{
$dup_array = $array;
$dup_array = array_unique($dup_array);
if(count($dup_array) != count($array))
{
return TRUE;
}
else
{
return FALSE;
}
}
?>
--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.
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