Solved

array_unique,  Can you ignore case sensitivity?

Posted on 2013-06-01
4
964 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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

763 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