Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.