brown2005 Posted June 4, 2009 Share Posted June 4, 2009 I have 20 players player1, player2, etc, etc. and 20 teams team1, team2, etc, etc. I would like to randomly assign the teams to the players. how can I do this please? Link to comment https://forums.phpfreaks.com/topic/160922-assigning-randomly-20-teams-to-20-players/ Share on other sites More sharing options...
Ken2k7 Posted June 4, 2009 Share Posted June 4, 2009 You can use rand in a while loop to generate a random number to represent the team a player would go into. Link to comment https://forums.phpfreaks.com/topic/160922-assigning-randomly-20-teams-to-20-players/#findComment-849239 Share on other sites More sharing options...
Mark Baker Posted June 4, 2009 Share Posted June 4, 2009 or shuffle() an array of the teams, then allocate $team[0] to $player[0], $team[1] to $player[1], etc Link to comment https://forums.phpfreaks.com/topic/160922-assigning-randomly-20-teams-to-20-players/#findComment-849243 Share on other sites More sharing options...
brown2005 Posted June 4, 2009 Author Share Posted June 4, 2009 hi, thanks for the replies, would you be able to show me the code for this please as I am very new to arrays and have not really used them. thanks Link to comment https://forums.phpfreaks.com/topic/160922-assigning-randomly-20-teams-to-20-players/#findComment-849251 Share on other sites More sharing options...
Ken2k7 Posted June 4, 2009 Share Posted June 4, 2009 Well give it a try and if something broke, post your code here and we can help; but if you want to request this to be written, there is the Freelance forum. Link to comment https://forums.phpfreaks.com/topic/160922-assigning-randomly-20-teams-to-20-players/#findComment-849264 Share on other sites More sharing options...
Psycho Posted June 4, 2009 Share Posted June 4, 2009 How do you have your teams and players stored/assigned now? Are they in a database, hard coded, or what? Show us how you create/utilize tehm now and more specific help can be given. Link to comment https://forums.phpfreaks.com/topic/160922-assigning-randomly-20-teams-to-20-players/#findComment-849295 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.