Removing Duplicate Entrys From Array ( Best ways )

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
127.0.0.1
Forum Newbie
Posts: 22
Joined: Mon Sep 12, 2005 8:59 pm

Removing Duplicate Entrys From Array ( Best ways )

Post by 127.0.0.1 »

I am looking for some opinions to learn what is the best way to do this and why.

The script is this:

for($b = 0; $b < $a; $b ++)
{
$entrysFound = 0;

for($c = 0; $c < $a; $c++)
{
if($array[$a] == $array[$c])
{
$entrysFound ++;
}
}

if($entrysFound > 1)
{
//Out put the duplicate and the number of duplicates found
echo "<br> Duplicate ".$search." ".$entrysFound ;
}
}

There is one array but there could be duplicate entry's, without going into the deep details of why there could be lets see other peoples views on removing duplicates from an array.

It is possible to search more than 1 array element for every iteration I don't know if that's something worth while doing or not?
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

please be aware we prefer php code to be posted using the

Code: Select all

forum tags. Read "How to Post Code on DevNetwork" in my signature for further details.
Post Reply