I have a project I have been working on and for the life of me I can not figure it out. I have a list of string, I need to remove the duplicates. I have try adding them to a array and do array_unique. but that did not work. I thought of comparing $a == $b with a off set of one so $b would be one behind, but I cant not think of how to do that.
List:
10.5.0.109www.foxnews.com
10.5.0.109www.foxnews.com
10.5.0.109www.foxnews.com
10.5.0.109www.foxnews.com
10.5.0.109www.foxnews.com
10.5.0.109ad.doubleclick.net
10.5.0.109ad.doubleclick.net
10.5.0.109ad.doubleclick.net
10.5.0.109adfarm.mediaplex.com
10.5.0.109ad.doubleclick.net
10.5.0.109analytics.live.com
10.5.0.109ad.doubleclick.net
10.5.0.109ad.doubleclick.net
Any Help would be great.
Jeff
Remove duplicate strings
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Remove duplicate strings
Maybe you didn't do it correctly, cuz array_unique() works great:
Yields:
Code: Select all
$a = array(
'10.5.0.109www.foxnews.com',
'10.5.0.109www.foxnews.com',
'10.5.0.109www.foxnews.com',
'10.5.0.109www.foxnews.com',
'10.5.0.109www.foxnews.com',
'10.5.0.109ad.doubleclick.net',
'10.5.0.109ad.doubleclick.net',
'10.5.0.109ad.doubleclick.net',
'10.5.0.109adfarm.mediaplex.com',
'10.5.0.109ad.doubleclick.net',
'10.5.0.109analytics.live.com',
'10.5.0.109ad.doubleclick.net',
'10.5.0.109ad.doubleclick.net',
);
print_r(array_unique($a));Code: Select all
Array
(
[0] => 10.5.0.109www.foxnews.com
[5] => 10.5.0.109ad.doubleclick.net
[8] => 10.5.0.109adfarm.mediaplex.com
[10] => 10.5.0.109analytics.live.com
)mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.