处理此数组时,每次引用该数组时都会给出通知,直到向其中添加某些内容。无论如何,所有输出都按预期工作。
通知截图:http: //imgur.com/75RGA
function create_round(&$arrTeam)
{
$numTeams = 4;
$used = array();
for ($i = 0; $i < $numTeams; $i++) {
if (!in_array($i, $used)) { //if i isnt already scheduled to play
for ($u = $numTeams-1; $u > $i; $u--) {
if (!in_array($u, $used) && !in_array($u, $arrTeam[$i]["games"])) { //if u isnt already scheduled to play and u hasnt been played by i before
$arrTeam[$i]["games"][sizeof($arrTeam[$i]["games"])] = $u;
$arrTeam[$u]["games"][sizeof($arrTeam[$u]["games"])] = $i;
$used[sizeof($used)] = $i;
$used[sizeof($used)] = $u;
echo($arrTeam[$i]["name"] . " VS " . $arrTeam[$u]["name"] . "<br>");
break;
}
}
}
}
var_dump($arrTeam);
}
function round_robin()
{
$numTeams = 4;
//Create array
$arrTeam = array(
$team = array(
"name" => "",
"games" => array()
)
);
//TEMP ASSIGNING NAMES
for ($i = 1; $i < $numTeams+1; $i++)
$arrTeam[$i-1]["name"] = "Team $i";
//Echo Round numbers
for ($i = 1; $i < $numTeams; $i++) {
echo("<br>Round $i<br>");
create_round($arrTeam);
}
}
round_robin();
应该禁用通知还是有更好的处理方法?
我尝试填充它,但代码长度增加了一倍而且非常混乱。