Thanks. This one actually works -

<?php


$list = array('david', 'dianne', 'phyllis', 'phillip') ;


    sort($list);
 
    echo '<br><br>Unique Pairs:';
        for($i = 0; $i < sizeof($list) ; $i++) {
            if($i > 0 && ($list[$i] == $list[$i-1]) ) {
            continue;
            }
        for($j = $i+1; $j < sizeof($list) ; $j++) {
                 if($list[$i] == $list[$j]) {
                continue;
                }
                if($list[$j] == $list[$j-1]) {
                continue;
                }
            echo '<br>' . $list[$i] . ' / ' . $list[$j];
        }
    }

?>

Bob <[EMAIL PROTECTED]> wrote:                               Hi David,
 
 ----- Original Message ----- 
 From: "David Gresser"
 > 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
 
 Not sure if this is what you need?
 It will select 6 unique names, so you could maybe modify it to suit.
 I used this in something similar.
 
 <?php
 $names = array("bob", "david", "dianne", "harry", "john", "harry", "henry", 
"mary", "phillip", "phyllis");
 $total = 6;
 
 // Create array to store results
 $results = array();
 // Keep looping until 6 unique names found
 while (count($results) < $total) 
 {
   $results[] = $names[array_rand($names)];
   $results = array_unique($results);
 }
 
 // Must loop though array as it may have holes
 foreach ($results as $item)
 {
   echo ucfirst($item) . " ";
 }
 
 // Show array with holes
 echo '<br /><br />';
 print_r($results);
 ?>
 
 You can't refer to names as $results[2] though, as you'll see if you run it.
 Not sure how to get rid of the array holes, as it didn't matter when I used it.
 Maybe someone else can comment?
 
 I gleaned all this from the downloadable manual, which is excellent, but 
haven't tried all the array functions yet.
 Regards, Bob Exton.
 
 
     
                               


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

Reply via email to