我已经生成了灯具,但想要在它们上添加日期生成。 因此,如果我有7轮,我会花28天,从现在开始的4天,从现在开始的8天,等等。
这样做的最佳方法是什么? 感谢
答案 0 :(得分:0)
使用来自php-cli的strtotime()的示例:
php > echo date("Y-m-d", strtotime("+4 days"));
2010-05-02
php > echo date("Y-m-d", strtotime("+8 days"));
2010-05-06
php > echo date("Y-m-d", strtotime("+12 days"));
2010-05-10
答案 1 :(得分:0)
这应该做你想要的,并允许不均匀的团队数量。由于四舍五入,日期可能并不完美:
$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);