Abrufen aller Termine für Montag und Dienstag für das nächste Jahr

Ich muss eine Liste der Daten (nur montags und dienstags) für die nächsten 12 Monate ab dem aktuellen Datum ausgeben.

Jan 2010
Di 12 Jan 2010
Mo 18 Jan 2010
Di 19 Jan 2010
Mo 25 Jan 2010
Februar 2010
Di 02 Feb 2010
Mo 08 Feb 2010
Di 09 Feb 2010
Mo 15 Feb 2010
Di 16 Feb 2010
Mo 22 Feb 2010
März 2010
Di 09 Mrz 2010
Mo, 15. März 2010
Di 16 Mrz 2010
...

Als PHP-Neuling habe ich mir gedachtstrtotime und die nächsten 52 Wochen zu durchlaufen ist der beste Weg zu gehen.

$blockedDatesInput = "08 Mar 2010,12 Apr 2010"; // dont show these dates
$blockedDates = explode ("," , $blockedDatesInput); // convert to array
$currentMonth = ""; // current month marker

// loop over the next 52 weeks to find Mondays and Tuesdays
for($i=0; $i<=52; $i++){
// build the month header
$monthReference = date("M Y", strtotime('+'.$i.' Week'));

// check if date exists in $blockeddate
if (!in_array(date("d M Y", strtotime('+'.$i.' Monday')), $blockedDates) || 
    !in_array(date("d M Y", strtotime('+'.$i.' Tuesday')), $blockedDates) ) {
     // check if we have to show a new month
     if(strcmp($monthReference, $currentMonth) <> 0){
       echo $monthReference.'<br />',"\n";
     }else{
      // output the dates
      echo date("D d M Y", strtotime('+'.$i.' Monday')).'<br />',"\n";
      echo date("D d M Y", strtotime('+'.$i.' Tuesday')).'<br />',"\n";
     }
       $currentMonth = date("M Y", strtotime('+'.$i.' Week'));
   }
}

Die Ausgabe von meinem Code ist jedoch

Jan 2010
Mo 18 Jan 2010
Di 12 Jan 2010
Mo 25 Jan 2010
Di 19 Jan 2010
Februar 2010
Mo 08 Feb 2010
Di 02 Feb 2010
Mo 15 Feb 2010
Di 09 Feb 2010
Mo 22 Feb 2010
Di 16 Feb 2010
März 2010
Mo 08 Mär 2010
Di 02 Mrz 2010
Mo, 15. März 2010
Di 09 Mrz 2010
Mo 22 Mär 2010
Di 16 Mrz 2010
Mo 29 Mär 2010
Di 23 Mrz 2010

Wie Sie sehen können, sind die Daten nicht in der richtigen Reihenfolge und ich bin ratlos, wo ich hier falsch liege.

Gibt es einen eleganteren / einfacheren Weg, dies zu lösen?

Die verwendete PHP-Version ist 5.2.11 und es besteht keine Aussicht, in Kürze zu 5.3 zu wechseln :-(

Danke für Ihre Hilfe.

Code unten Modifikation wie von Aly vorgeschlagen. Das Computerdatum wurde von Di, 12.01.2010 auf Mi, 13.01.2010 geändert, um die Ausgabe zu testen.

$blockedDatesInput = "08 Mar 2010,12 Apr 2010"; // dont show these dates
$blockedDates = explode ("," , $blockedDatesInput); // convert to array
$currentMonth = ""; // current month marker

// loop over the next 52 weeks to find Mondays and Tuesdays
for($i=0; $i<=52; $i++){
// build the month header
$monthReference = date("M Y", strtotime('+'.$i.' Week'));

// check if date exists in $blockeddate
if (!in_array(date("d M Y", strtotime('+'.$i.' Monday')), $blockedDates) || 
    !in_array(date("d M Y", strtotime('+'.$i.' Tuesday')), $blockedDates) ) {
     // check if we have to show a new month
     if(strcmp($monthReference, $currentMonth) <> 0){
       echo $monthReference.'<br />',"\n";
     }else{
      // output the dates (changed the order as suggested by Aly)
      echo date("D d M Y", strtotime('+'.$i.' Tuesday')).'<br />',"\n";
      echo date("D d M Y", strtotime('+'.$i.' Monday')).'<br />',"\n";          
     }
       $currentMonth = date("M Y", strtotime('+'.$i.' Week'));
   }
}

Erneut in der falschen Reihenfolge ausgeben.

Jan 2010
Di 19 Jan 2010
Mo 18 Jan 2010
Di 26 Jan 2010
Mo 25 Jan 2010
Februar 2010
Di 09 Feb 2010
Mo 08 Feb 2010
Di 16 Feb 2010
Mo 15 Feb 2010
Di 23 Feb 2010
Mo 22 Feb 2010

Antworten auf die Frage(4)

Ihre Antwort auf die Frage