Heres what I have:
Code: Select all
<?php
$thefile=file($usersfile);
$namesarray=explode("|", $thefile[0]);
array_shift($namesarray);
$memname = array_rand ($namesarray);
?>Moderator: General Moderators
Code: Select all
<?php
$thefile=file($usersfile);
$namesarray=explode("|", $thefile[0]);
array_shift($namesarray);
$memname = array_rand ($namesarray);
?>Code: Select all
<?php
$name_list = Array('apple','banana','cherry');
$used_list = Array('apple');
//lets say your code has chosen banana this time
$new_name = 'banana';
//now loop through the $used_list and see if banana is in there
$is_in_there = false;
for($i=0; $i<count($used_list); $i++)
{
if($used_list[$i]==$new_name) { $is_in_there = true; }
}
//now do something depending on the results
if($is_in_there)
{
//the new_name IS in the used_list so do something..
}
else
{
push_array($used_list, $new_name);
//the new_name has been added to the used_list
//now do something else...
}
?>Code: Select all
unset($namesarrayї1])Code: Select all
$ckname = array_rand($namesarray);
if(!in_array("$ckname", $used)){
$memname=$ckname;
$usedї]=$ckname;
}Code: Select all
<?php
$cname = array_rand($namesarray);
$ckname = $namesarray[$cname];
if(!in_array("$ckname", $used)){
$memname=$ckname;
$used[]=$ckname;
}
?>Code: Select all
<?php
// build test name array, use your file for this step
for($i=0; $i<24; $i++){
$namesarray[]="DUFF".$i;
}
// end test array
$total_available_players = count($namesarray);
$total_players_per_team = 3;
$total_teams_to_populate = 8;
$t=1;
$p=0;
while($t <= $total_teams_to_populate){
print"<p>team $t contains:";
while($p < $total_players_per_team){
$randomkey = array_rand($namesarray);
$ckname = $namesarray[$randomkey];
if(!in_array("$ckname", $used)){
$memname=$ckname;
$used[]=$ckname;
print" | $memname";
$p++;
}
}
unset($p);
$t++;
}
?>