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.


Reply via email to