1
此代码有几个部分。第一部分是创建灯具。Foreach时间循环不起作用
$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]);
}
}
这段代码使用分解代码从上面放到表中。出于某种原因,输入数据库的日期出现在0000-00-00 00:00:00。
有没有人可以看到解决这个问题?
编辑:循环不工作? 我在实际循环中遗漏了什么?
除了$ awaydetails [2]之外,所有内容都将触及数据库。 数据库中的该字段设置为日期时间。 我认为这可能不是需要的? 上述代码中我的日期格式将进入数据库中? – sark9012 2010-05-04 13:47:54
以这种格式“0000-00-00 00:00:00”。那就是'YYYY-MM-DD HH:mm:ss'。 strtotime()会导致自“unix时代”以来的秒数。使用PHP的'date()'函数将它放到上面的表单中。我相信,日期(“Y-m-d H:i:s”,$ time)'应该有效。 – 2010-05-04 17:20:23