title: Getting all dates for Mondays and Tuesdays for the next year
body: <p>I need to output a list of dates (only Mondays and Tuesdays) for the next 12 months from current date like so:</p>
  
  <p>
  Jan 2010<br />
  Tue 12 Jan 2010<br />
  Mon 18 Jan 2010<br />
  Tue 19 Jan 2010<br />
  Mon 25 Jan 2010<br />
  
  Feb 2010<br />
  Tue 02 Feb 2010<br />
  Mon 08 Feb 2010<br />
  Tue 09 Feb 2010<br />
  Mon 15 Feb 2010<br />
  Tue 16 Feb 2010<br />
  Mon 22 Feb 2010<br />
  
  Mar 2010<br />
  Tue 09 Mar 2010<br />
  Mon 15 Mar 2010<br />
  Tue 16 Mar 2010<br />
  ...
  </p>
  
  <p>Being new to PHP I figured <b>strtotime</b> and looping over the next 52 weeks is the best way to go.</p>
  
  <pre><code>$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&lt;=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) &lt;&gt; 0){
         echo $monthReference.'&lt;br /&gt;',"\n";
       }else{
        // output the dates
        echo date("D d M Y", strtotime('+'.$i.' Monday')).'&lt;br /&gt;',"\n";
        echo date("D d M Y", strtotime('+'.$i.' Tuesday')).'&lt;br /&gt;',"\n";
       }
         $currentMonth = date("M Y", strtotime('+'.$i.' Week'));
     }
  }
  </code></pre>
  
  <p>However the output from my code is </p>
  
  <p>
  Jan 2010<br />
  Mon 18 Jan 2010<br />
  Tue 12 Jan 2010<br />
  Mon 25 Jan 2010<br />
  Tue 19 Jan 2010<br />
  Feb 2010<br />
  Mon 08 Feb 2010<br />
  Tue 02 Feb 2010<br />
  Mon 15 Feb 2010<br />
  Tue 09 Feb 2010<br />
  Mon 22 Feb 2010<br />
  Tue 16 Feb 2010<br />
  Mar 2010<br />
  Mon 08 Mar 2010<br />
  Tue 02 Mar 2010<br />
  Mon 15 Mar 2010<br />
  Tue 09 Mar 2010<br />
  Mon 22 Mar 2010<br />
  Tue 16 Mar 2010<br />
  Mon 29 Mar 2010<br />
  Tue 23 Mar 2010<br />
  </p>
  
  <p>As you can see the dates are not in the right order and I am at a loss where I am going wrong here.</p>
  
  <p>Is there a more elegant / simple way to solve this?</p>
  
  <p>Version of PHP used is 5.2.11 and no prospect of going to 5.3 anytime soon :-(</p>
  
  <p>Thanks for your help.</p>
  
  <p>Code below modification as suggested by Aly.
  Changed the computer date from Tue, 12/01/2010 to Wed, 13/01/2010 to test the output.</p>
  
  <pre><code>$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&lt;=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) &lt;&gt; 0){
         echo $monthReference.'&lt;br /&gt;',"\n";
       }else{
        // output the dates (changed the order as suggested by Aly)
        echo date("D d M Y", strtotime('+'.$i.' Tuesday')).'&lt;br /&gt;',"\n";
        echo date("D d M Y", strtotime('+'.$i.' Monday')).'&lt;br /&gt;',"\n";          
       }
         $currentMonth = date("M Y", strtotime('+'.$i.' Week'));
     }
  }
  </code></pre>
  
  <p>Output again in the wrong order.</p>
  
  <p>
  Jan 2010<br />
  Tue 19 Jan 2010<br />
  Mon 18 Jan 2010<br />
  Tue 26 Jan 2010<br />
  Mon 25 Jan 2010<br />
  Feb 2010<br />
  Tue 09 Feb 2010<br />
  Mon 08 Feb 2010<br />
  Tue 16 Feb 2010<br />
  Mon 15 Feb 2010<br />
  Tue 23 Feb 2010<br />
  Mon 22 Feb 2010<br />
  </p>