dsu5188 2010-05-03 17:39
浏览 46
已采纳

每隔几天添加一个日期

I have some code that generates fixtures, I am looking to add a fixture date to the code.

$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 is the amount of teams in the league. I want to add a variable for every 4 days, and for every round of fixtures generated, I want to add 4 days onto the previous round.

For example, if today is 3rd may, i want 3rd may for first fixture, 7th may for second fixture, 11th may for third fixture.

By fixture i mean round which includes a set of fixtures!

How do I add 4 days to a strotime variable everytime the rounds increase?

  • 写回答

2条回答 默认 最新

  • dsdsm2016 2010-05-03 18:39
    关注

    If I understand your question correctly, you just want each round to have an associated date. You've got an array of $rounds, so could you not just create a correspondingly-keyed array to hold the round dates?

    ...
    $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)."
    ";
    //gives
    //2010-05-03
    //2010-05-07
    //2010-05-11
    //etc
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记