Obtendo todas as datas para segundas e terças-feiras para o próximo ano

Preciso apresentar uma lista de datas (somente às segundas e terças-feiras) para os próximos 12 meses a partir da data atual da seguinte forma:

Jan 2010
Ter 12 jan 2010
Seg 18 jan 2010
Ter 19 jan 2010
Seg 25 jan 2010
Fev 2010
Ter 02 fev 2010
Seg 08 fev 2010
Ter 09 fev 2010
Seg 15 fev 2010
Ter 16 fev 2010
Seg 22 fev 2010
Mar 2010
Ter 09 mar 2010
Seg 15 mar 2010
Ter 16 de março de 2010
...

Sendo novo em PHP eu percebistrtotime e looping nas próximas 52 semanas é o melhor caminho a percorrer.

$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'));
   }
}

No entanto, a saída do meu código é

Jan 2010
Seg 18 jan 2010
Ter 12 jan 2010
Seg 25 jan 2010
Ter 19 jan 2010
Fev 2010
Seg 08 fev 2010
Ter 02 fev 2010
Seg 15 fev 2010
Ter 09 fev 2010
Seg 22 fev 2010
Ter 16 fev 2010
Mar 2010
Seg 08 mar 2010
Ter 02 Mar 2010
Seg 15 mar 2010
Ter 09 mar 2010
Seg 22 mar 2010
Ter 16 de março de 2010
Seg 29 mar 2010
Ter 23 de março de 2010

Como você pode ver as datas não estão na ordem correta e eu estou em uma perda onde eu estou errado aqui.

Existe uma maneira mais elegante / simples de resolver isso?

A versão do PHP usada é 5.2.11 e não há perspectiva de ir a 5.3 em breve :-(

Obrigado pela ajuda.

Codifique abaixo da modificação como sugerido por Aly. Alterou a data do computador de terça, 12/01/2010 para quarta, 13/01/2010 para testar a saída.

$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'));
   }
}

Saída novamente na ordem errada.

Jan 2010
Ter 19 jan 2010
Seg 18 jan 2010
Ter 26 jan 2010
Seg 25 jan 2010
Fev 2010
Ter 09 fev 2010
Seg 08 fev 2010
Ter 16 fev 2010
Seg 15 fev 2010
Ter 23 fev 2010
Seg 22 fev 2010

questionAnswers(4)

yourAnswerToTheQuestion