我有一些代码,生成灯具,我希望添加一个灯具日期的代码。
$totalRounds = $teams - 1;
$matchesPerRound = $teams / 2;
$rounds = array();
for ($i = 0; $i < $totalRounds; $i++) {
$rounds[$i] = array();
}
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]";
}
}$team是联盟中的球队数量。我想为每4天添加一个变量,并且对于每一轮生成的装备,我想在前一轮的基础上添加4天。
例如,如果今天是5月3日,我希望第一场比赛是5月3日,第二场比赛是5月7日,第三场比赛是5月11日。
我所说的fixture指的是圆形,它包括一组fixture!
如何在每次轮数增加时将4天添加到strotime变量中?
发布于 2010-05-04 02:39:31
如果我没理解错的话,你只是希望每一轮都有一个相关的日期。您已经有了一个$rounds数组,所以您不能创建一个对应的键值数组来保存舍入日期吗?
...
$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) echo date("Y-m-d",$time)."\n";
//gives
//2010-05-03
//2010-05-07
//2010-05-11
//etc发布于 2010-05-04 01:43:08
你调查过strtotime吗?它允许如下语法:
$future_date = strtotime('+4 days');
$even_further_in_the_future = strtotime('+4 days', $future_date);
$arbitrary_start_date = strtotime('+4 days', strtotime('May 25th, 2010'));https://stackoverflow.com/questions/2759979
复制相似问题