Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare 2 lists of numbers and only print unique #'s

Status
Not open for further replies.
May 13, 2005
56
US
I have 2 arrays build with numbers in both, I want to compare the numbers from both group and only print the unique numbers from the second group.

So, for example
array1[0]=1
array1[1]=2
array1[2]=3
array1[3]=4

array2[0]=5
array2[1]=4
array2[2]=3
array2[3]=2
array2[4]=1

So in this example, I would like it to display 5 or array2[0]

I was trying a couple of nested loops, but I cant seem to get it.

for example:

Code:
$i=0;
while ($i < 5) {
$a=0;
    while ($a < 4){
        if ($array2[$i] == $array1[$a]){
        $i++; 
        }
    $a++;
    }
print array2[$i];
$i++;
}

Help please :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top