Solved

array_unique,  Can you ignore case sensitivity?

Posted on 2013-06-01
4
1,007 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

Industry Leaders: 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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

632 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