此代码有几个部分。第一部分是创建灯具。
$totalRounds = $teams - 1;
$matchesPerRound = $teams / 2;
$rounds = array();
$roundDates = array();
$curTime = time();
for ($i = 0; $i < $totalRounds; $i++) {
$rounds[$i] = array();
$numDays = $i * 4;
$roundDates[$i] = strtotime("+".$numDays." days",$curTime);
}
foreach($roundDates as $time) {
for ($round = 0; $round < $totalRounds; $round++) {
for ($match = 0; $match < $matchesPerRound; $match++) {
$home = ($round + $match) % ($teams - 1);
$away = ($teams - 1 - $match + $round) % ($teams - 1);
// Last team stays in the same place while the others
// rotate around it.
if ($match == 0) {
$away = $teams - 1;
}
$rounds[$round][$match] = "$user[$home]~$team[$home]@$user[$away]~$team[$away]~$time";
}
}
}
在上面的代码中,每一轮灯具都有一段时间。 在代码的最后我添加了$ time。
for ($i = 0; $i < count($rounds); $i++)
{
foreach ($rounds[$i] as $r)
{
$seperateUsers = explode("@",$r);
$homeinfo = $seperateUsers[0];
$awayinfo = $seperateUsers[1];
$homedetails = explode("~",$homeinfo);
$awaydetails = explode("~",$awayinfo);
$database->addFixtures($homedetails[0], $homedetails[1], $awaydetails[0], $awaydetails[1], $awaydetails[2]);
}
}
这段代码使用分解上面的代码放入表中。出于某种原因,输入数据库的日期出现在00:00:00。
有没有人可以看到解决这个问题?
编辑:循环不起作用? 我在实际循环中遗漏了什么吗?
答案 0 :(得分:1)
听起来像$ homedetails [0]等未设置。您可以在调用addFixtures()
之前使用调试器检查这些值,或者在调用之前添加简单的echo
或var_dump()
语句来检查它们。