Matchlist

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
mevets
Forum Newbie
Posts: 23
Joined: Fri Sep 15, 2006 10:06 am

Matchlist

Post 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?
User avatar
kaszu
Forum Regular
Posts: 749
Joined: Wed Jul 19, 2006 7:29 am

Post by kaszu »

mevets
Forum Newbie
Posts: 23
Joined: Fri Sep 15, 2006 10:06 am

Post 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().
Post Reply