普通网友 2010-04-28 14:38
浏览 13
已采纳

释放灯具的好方法

Hey, my problem is as follows, I am trying to create code where a set of sporting fixtures are created with dates on. Say I have 8 teams, with 7 rounds of fixtures.

I have generated the fixtures, but want to add a date generation on them. So if i had 7 rounds, I would put 28 days and it would make each round 4 days from now, 8 days from now, etc.

What would be the best way to go about doing this? Thanks

  • 写回答

2条回答 默认 最新

  • dtbhp60824 2010-04-28 16:49
    关注

    This should do what you want and allows for an uneven number of teams. Dates might not be perfect because of the rounding down:

        $teams = array("TEAM A","TEAM B","TEAM C","TEAM D","TEAM E", "TEAM F","TEAM G","TEAM H","TEAM I");
        $days = 28;
        $rounds = count($teams) -1;
    
        //Number of Days Between Fixtures
        $daysBetweenFixtures = floor($days / $rounds);
    
    
        $fixtures = array();
    
        for($i =0; $i < count($teams); $i++) {
            //Calculate Date of this round of fixtures
            $date  = date("D d M Y",mktime(0, 0, 0, date("m")  , date("d")+ ($i * $daysBetweenFixtures) , date("Y")));
    
            $hasFixtureToday = array();
    
            for($j=$i; $j<$i+count($teams);  $j=$j+2) {
                $homeTeam = $teams[$j % count($teams)];         
                $awayTeam = $teams[($j+1) % count($teams)];
    
                if(!in_array($homeTeam,$hasFixtureToday) && !in_array($awayTeam,$hasFixtureToday)) {
                    $fixtures[$date][] = "{$homeTeam} vs {$awayTeam}";
                    $hasFixtureToday[] = $homeTeam;
                    $hasFixtureToday[] = $awayTeam;
                }
            }
        }
        print_r($fixtures);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?