Page 1 of 1

checking for multiple values within an array

Posted: Mon Nov 27, 2006 10:56 am
by hame22
Hi I have an array of email addresses.

What I would like to do is search this array to see if there are multiples of the same email address, so I can then return an error.

Is there a function that allows you to do this?

thanks in advance.

Posted: Mon Nov 27, 2006 11:02 am
by Jenk

Code: Select all

if (count($array) !== count(array_unique($array))) echo 'Duplicates detected!';

Posted: Mon Nov 27, 2006 12:16 pm
by aaronhall
Or, as you are loading the addresses into the array:

Code: Select all

if(in_array($thisEmail, $emailAddresses)) { echo "duplicate found"; exit; }
will potentially find duplicates before the entire array is loaded.

Posted: Tue Nov 28, 2006 5:02 am
by hame22
thanks thats great!