Solved

array_unique,  Can you ignore case sensitivity?

Posted on 2013-06-01
4
892 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
  • 2
4 Comments
 
LVL 58

Expert Comment

by:Gary
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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…
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…
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 …

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now