Jump to content

Group random array elements


smproph

Recommended Posts

I have it to where it groups two parts of the Array randomly but I need to make it where it won't pair the same together, or if it has already been paired with a team then use another team. Each value of the array can only be used once.

 

Here is my code

shuffle($teamname);

$loopCount = $games;

for ($i = 0; $i < $loopCount; $i++) {
    $player1 = array_pop($teamname);
    $player2 = array_pop($teamname);
if(is_null($player1))
{
	echo 'Not enough different teams to create '.$games.' games';
	break;
}
    // output to screen
    echo "Team: " . $player1 . " Vs Team: " . $player2 . "<br />"; 

}
	}

 

Link to comment
https://forums.phpfreaks.com/topic/225552-group-random-array-elements/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.