Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-28-2013, 02:33 PM   PM User | #1
instaunt
New Coder

 
Join Date: Apr 2010
Posts: 92
Thanks: 4
Thanked 0 Times in 0 Posts
instaunt is an unknown quantity at this point
How do you find ONLY unique strings in an array?

I have a list of 4000 web addresses. I need to extract all the web addresses that only occur once. Any that are in the list twice or more I don't want to know about.

How do you extract unique strings?

Thanks
Mike
instaunt is offline   Reply With Quote
Old 02-28-2013, 02:41 PM   PM User | #2
Arcticwarrio
Regular Coder

 
Arcticwarrio's Avatar
 
Join Date: May 2012
Location: UK
Posts: 597
Thanks: 15
Thanked 67 Times in 67 Posts
Arcticwarrio is on a distinguished road
PHP Code:
<?php
$input 
= array("a" => "green""red""b" => "green""blue""red");
$result array_unique($input);
print_r($result);
?>
The above example will output:

Array
(
[a] => green
[0] => red
[1] => blue
)
__________________
There are 10 types of people on CodingForums,
Those who understand Binary and those who dont.
Arcticwarrio is offline   Reply With Quote
Old 03-01-2013, 03:46 PM   PM User | #3
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,882
Thanks: 9
Thanked 291 Times in 287 Posts
Dormilich is on a distinguished road
@arctic: I think he meant not to exclude duplicate values, but to find values that that are present once and only once.

array_count_values() (and array_filter()) should be what you’ll need.
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:44 AM.


Advertisement
Log in to turn off these ads.