Jump to content

Email address duplicates


_tina_

Recommended Posts

Hi,

 

I have an array of email addresses, I'm trying to figure out how to check for duplicates.

 

I have read various form posts on the topic but can't seem to get anything that works for me.  Does anybody have any experience with this?

 

Thanks in advance!

Link to comment
Share on other sites

Yup, my method is too loop through the array and check it manually one by one:

 

Theory =

 

Start Array with Duplicates

Create new array (for this purpose ill name it "NewArray").

Loop through each item of Start Array, and add it to NewArray as long as it doesnt exist.

Then your left with a new array.

 

An Example: (UNTESTED)

<?php

$Array = array(
"someemail@test.com",
"email@test.com",
"test@email.com",
"someemail@test.com",
"test@someemail.com"
);

$nArray = array();

for($i=0;$i<count($Array);$i++){
if(!isset($nArray[$Array[$i]])){
	$nArray[$Array[$i]] = count($nArray) - 1;
}

}
$nArray = array_flip($nArray);

?>

 

Hope this helps,

-CB-

Link to comment
Share on other sites

<?php
$array  = array(
"someEmail@test.com",
"email@test.com",
"test@email.com",
"someemail@test.com",
"test@someemail.com"
);

$array  = array_map("strtolower", $array);
$unique = array_unique($array, SORT_STRING);

echo '<pre>' . "\n\tStart array:\n\n" . print_r($array, true) . "\n\n" . '</pre>';
echo '<pre>' . "\n\tUnique array:\n\n" . print_r($unique, true) . '</pre>';
?>

 

 

Output:

Start array:

Array
(
    [0] => someemail@test.com
    [1] => email@test.com
    [2] => test@email.com
    [3] => someemail@test.com
    [4] => test@someemail.com
)


Unique array:

Array
(
    [0] => someemail@test.com
    [1] => email@test.com
    [2] => test@email.com
    [4] => test@someemail.com
)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.