Thanks. I would like to get it so that duplicates like  david - dianne   and 
dianne - david  were elminated so for say a list of three names:

david
dianne
phillip

I would only end up with 3 pairs

david dianne
david phillip
dianne phillip



[EMAIL PROTECTED] wrote:                               ----- Original Message 
----- 
 From: "David"
 
 Help! following up on advise I got from an earlier question, I've been
 struggling with this for hours. I'm trying to generate a simple list
 of unique pairs from a list of 4 items for example, I start with
 $names = "david,dianne,phillip,phyllis"
 
 I explode them into an array but  I can't figure out how to
 generate the unique list of pairs. I don't want relults like
 "david david"
 
 I've tried some recursive stuff but I keep winding up in infinate loops.
 
 Thanks
 
 David
 -------------------------------
 Hello David,
                    If each item is unique like in your list $names = 
 "david,dianne,phillip,phyllis" then you can loop it like a bubble sort.
 
 $names = "david,dianne,phillip,phyllis";
 $namearray = explode(",", $names);
 $items = (count($namearray) - 1);
 // "-1" for zero indexed
 $index3 = 0;
 for($index1 = 0, $index1 < $items, $index1++)
 // "<" so that this loop never reaches the last item
   {
   for($index2 = $index1 + 1, $index2 <= $items, $index2++)
   // form the next item to the last item
     {
     $outarray[$index3] = $namearray[$index1] . " " . $namearray[$index2];
     }
   }
 
 I have been watching this thread with interest. The problem with this 
 approach is that the number of permutations increase factorialy with the 
 number of items so you would soon be using very vast tables for the high 
 number of permutations.
 
 Thanks, Rob. 
 
 
     
                               


[Non-text portions of this message have been removed]

Reply via email to