Birkaç günde bir tarih ekleme

2 Cevap

Ben armatürleri üreten bazı kod var, ben kodu bir fikstür tarih eklemek için arıyorum.

$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.

Bugün 3 Mayıs Örneğin, ben ilk fikstür, ikinci fikstür için 7 Mayıs, üçüncü fikstür için 11 Mayıs için 3 Mayıs istiyorum.

Fikstür tarafından i armatürleri kümesi içerir yuvarlak demek!

Nasıl 4 gün tur artırmak bir strotime değişken her şey eklerim?

2 Cevap

Sorunuzu doğru anlamak, sadece her bir yuvarlak ilişkili bir tarihe sahip olmak istiyorum. Sen $rounds bir dizi var, bu yüzden sadece yuvarlak tarihleri ​​tutmak için buna-anahtarlı bir dizi oluşturmak değil mi?

...
$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