Wes1890 Posted August 16, 2006 Share Posted August 16, 2006 Im back...I'm needing help on a script that picks 8 people and pairs them up... but not to pair up the same pair until all people have been mixed to their max...examplepeople:abcdefgh(8 people with short names) (in an array)i want it to mix up the 8 like this:a - db - eg - hf - ceach person have 7 other people to pair up with... which makes it 64 total mix ups (i think i figured that right... lol 8*8.. it might be 7*7=49 anywyas)so until each person is matched up with each of the other 7 people i don't want them to be paired up with someone they have been already paired up with.... get me?any help will be awesome... thanks Quote Link to comment Share on other sites More sharing options...
trq Posted August 16, 2006 Share Posted August 16, 2006 Very ugly but works....[code=php:0]#!/usr/bin/php<?php function ugly_random_pairing($array) { while (count($arr) > 0) { $akey = array_rand($arr); $aval = $arr[$akey]; unset($arr[$akey]); $bkey = array_rand($arr); $bval = $arr[$bkey]; unset($arr[$bkey]); $keys[] = $aval; $vals[] = $bval; } return array_combine($keys,$vals); } $arr = array('a','b','c','d','e','f','g','h'); print_r(ugly_random_pairing($arr);?>[/code] Quote Link to comment Share on other sites More sharing options...
Wes1890 Posted August 16, 2006 Author Share Posted August 16, 2006 it returns"Array"thats it... ? Quote Link to comment Share on other sites More sharing options...
Jeremysr Posted August 16, 2006 Share Posted August 16, 2006 Maybe something like this?[code]<?php$people = array('a','b','c','d','e','f','g','h');for ($x = 0; $x < 8; $x++) { for ($y = 0; $y < 8; $y++) { if ($x != $y) { echo ("$people[$x] $people[$y]<br />"); } }}?>[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted August 16, 2006 Share Posted August 16, 2006 [quote]it returns"Array"thats it... ?[/quote]Not here it does'nt. Show me how your using it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.