-1

我正在寻找创建一个蛇草稿脚本。我希望订单上升到阵列然后返回阵列。

 $teams = array('mike','jim','chris','tim');

我希望订单是

 Round 1
 Mike, Jim, Chris, Tim
 Round 2
 Tim, Chris, Jim, Mike

那将是两轮。我希望这是命令并重复,但我无法用 PHP 弄清楚。我已经尝试从我的数据库中的选秀中获得最后一个选秀权。$lastpick =(最后提交到我的数据库的团队名称);

if(empty($lastpick) && $teams(0) == 'mike'){
  //do this
}else if($lastpick == $teams(0) && $teams(1) == 'jim'){
 // do this
}else if($lastpick == $teams(1) && $teams(2) == 'chris'){
  // do this
}else if($lastpick == $teams(2) && $teams(3) == 'tim'){
  // do this
}else if($lastpick == $teams(3) && $teams(3) == 'tim'){
  // do this
}

接下来我会怎么做?这得到了 mike,jim,chris,tim 然后再 tim 的顺序,但我不能让它回到我阵列中的第三个团队。任何帮助都会非常感谢。

4

1 回答 1

1

我不完全确定你为什么需要&& $teams(x) == 'yyy'在每个语句中,你已经知道它们是什么,因为顺序是定义的,如果它们发生变化,你需要更新所有这些语句。

您将需要某种形式的标志来定义您当前正在向上或向下移动的方式。

boolean movingUp = true;

if(empty($lastpick)) { // first team }
else if(movingUp && $lastpick == $teams(0)) { // second team }
else if(movingUp && $lastpick == $teams(1)) { // third team }
else if(movingUp && $lastpick == $teams(2)) { movingUp = false; // fourth team }
else if(!movingUp && $lastpick == $teams(3)) { // fourth team }
else if(!movingUp && $lastpick == $teams(2)) { // third team }
else if(!movingUp && $lastpick == $teams(1)) { // second team }
else if(!movingUp && $lastpick == $teams(1)) { movingUp = true; $lastpick = null; // first team }

你不需要有一个$lastpick == $teams(3),因为一旦你选择了倒数第二个,你就知道下一个动作,同时向上移动,是最后一个团队。

于 2013-07-29T15:19:57.870 回答