Page 1 of 1

Matchlist

Posted: Fri Jan 26, 2007 2:03 pm
by mevets
I'm trying to create an array of numbers derived from a larger set of numbers.

For example I have a list like

Code: Select all

1,3,4,2,5,1,4,1,2,3,1,3
I want to take one of each number and input into an array so my new array would be

Code: Select all

1,3,4,2,5
I essentially want one copy of each number in the list. Order does not matter.

Here is my attempt

Code: Select all

$mindex = 0; $matchCont = true;
while($matchCont)
{
	if ($allCounts[$mindex] = $guiCount[0])
		$match = true;
	if ($mindex >= sizeof($allCounts) - 1)
		$matchCont = false;
	echo $guiCount[0] . " - " . $mindex . "<br>";
	$mindex++;
}
if (!$match)
	$allCounts[sizeof($allCounts)] = $guiCount[0];
Is there any easier way? Say for example I could see if a number is in a matchlist delimited by commas and add it to the list if it was not in there and refuse to add it if it is already in the list?

Posted: Fri Jan 26, 2007 2:06 pm
by kaszu

Posted: Fri Jan 26, 2007 10:06 pm
by mevets
Awesome! It works perfectly. My only problem is that it would not put the values in sequencial keys. To solve that problem I used array_values().