Solved

array_unique,  Can you ignore case sensitivity?

Posted on 2013-06-01
4
980 Views
Last Modified: 2013-06-01
I have a php array that has multiples of the same email address.  I want to use something like array_unique to get a list of unique emaill addresses.  However I am finding that if the same email address where the letter case is used differently array_unique sees them as two different items.  ie.  David@webcahoot.com and david@WebCahoot.com are not unique in $result.  How can I make this happen. Thanks

$result = array_unique($email_list);

Open in new window

0
Comment
Question by:Luey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39213397
There is a caveat in your question - email addresses can be case sensitive.
The part before the @, anything after it should be lowercase.
0
 

Author Comment

by:Luey
ID: 39213419
What I am trying to eliminate is sending the same email to

David@Webcahoot.com
david@webcahoot.com
DAVID@WEBCAHOOT.com

any suggestions.  Can't I just make it all lower case with strtolower();  before creating my array?
0
 
LVL 58

Assisted Solution

by:Gary
Gary earned 250 total points
ID: 39213423
http://www.php.net/manual/en/function.array-unique.php#78801

function array_iunique($email_list) {
     return array_intersect_key($email_list,array_unique(
                  array_map('strtolower',$email_list)));
 }
0
 
LVL 2

Accepted Solution

by:
vid_yag earned 250 total points
ID: 39213439
Hi Luey,
You can get unique value with following code:
<?php
$emailArr = array(
'David@webcahoot.com',
'david@WebCahoot.com',
'abc@KKK.com',
'ABC@kkk.com'
);
$uniqueArray =  array_intersect_key($emailArr, array_unique(array_map("StrToLower",$emailArr)));
print_r($uniqueArray);
?>

Open in new window

This outputs:
Array ( [0] => David@webcahoot.com [2] => abc@KKK.com ) 

Open in new window



P.S. I gave same answer as GaryC123
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question