David Gresser wrote: > > 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] <mailto:listgroups%40ozwebwiz.com> 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 > ------------------------------- >
> <http://docs.yahoo.com/info/terms/>| Unsubscribe > <mailto:[EMAIL PROTECTED]> > Recent Activity > > * > 13 > New Members > > <http://groups.yahoo.com/group/php-list/members;_ylc=X3oDMTJlaXJkMzQ3BF9TAzk3MzU5NzE0BGdycElkAzMwMzAzMQRncnBzcElkAzE3MDUwMDU3MDMEc2VjA3Z0bARzbGsDdm1icnMEc3RpbWUDMTE4OTQ2Njk2OQ--> > > Visit Your Group > <http://groups.yahoo.com/group/php-list;_ylc=X3oDMTJkMWVqcjVpBF9TAzk3MzU5NzE0BGdycElkAzMwMzAzMQRncnBzcElkAzE3MDUwMDU3MDMEc2VjA3Z0bARzbGsDdmdocARzdGltZQMxMTg5NDY2OTY5> > > > Yahoo! Groups > > Get info and support > <http://us.ard.yahoo.com/SIG=12jlsbmi5/M=493064.10972170.11554072.8674578/D=groups/S=1705005703:NC/Y=YAHOO/EXP=1189474169/A=4706131/R=0/SIG=11f8fj6tf/*http://tech.groups.yahoo.com/group/samsunghd/> > > on Samsung HDTVs > > and devices. > > Yoga Groups > > Find Enlightenment > <http://us.ard.yahoo.com/SIG=12j102gis/M=493064.10771301.11554070.8674578/D=groups/S=1705005703:NC/Y=YAHOO/EXP=1189474169/A=4699085/R=0/SIG=11pv8cj55/*http://advision.webevents.yahoo.com/yogazone/index.html> > > & exchange insights > > with other members > > Fitness Edge > > A Yahoo! Group > <http://us.ard.yahoo.com/SIG=12jq8q9f7/M=493064.11135487.11710473.8674578/D=groups/S=1705005703:NC/Y=YAHOO/EXP=1189474169/A=4834086/R=0/SIG=11ikjqbtm/*http://sports.groups.yahoo.com/group/accelerade/> > > about sharing fitness > > and endurance goals. > > . > David - The non-elegant, non-exciting, but fully functional brute force method would be: <?php $list = array('a','b','c','d','d','e','b','b','c','d','d'); echo 'Unsorted List:'; for($i = 0; $i < sizeof($list); $i++) { echo '<br>' . $list[$i]; } sort($list); echo '<br><br>Sorted List:'; for($i = 0; $i < sizeof($list); $i++) { echo '<br>' . $list[$i]; } 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]; } } ?> Result: Unsorted List: a b c d d e b b c d d Sorted List: a b b b c c d d d d e Unique Pairs: a / b a / c a / d a / e b / c b / d b / e c / d c / e d / e Hope that helps, Mike [Non-text portions of this message have been removed]
