title: Get array of dates seperated by weeks for a given month and year in php
body: <p>Hi I am collecting the month and the year from a form and want to generate an array of the number of dates on that particular month seperated by weeks assuming <code>sunday</code> as the beginning of week.</p>
  
  <p>For example, if the input is <code>month=January</code> and <code>year=2018</code>, the desired result is </p>
  
  <pre><code>$array_of_dates =Array ( [Week 1] =&gt; '01/01/2018',.....,'06/01/2018'
                           [Week 2] =&gt; '07/01/2018',.....,'13/01/2018' 
                           [Week 3] =&gt; '14/01/2018',.....,'20/01/2018'
                           [Week 4] =&gt; '21/01/2018',.....,'27/01/2018' 
                           [Week 5] =&gt; '28/01/2018',.....,'31/01/2018' ) 
  </code></pre>
  
  <p>I tried this</p>
  
  <pre><code>function weeks_in_month($month, $year) {
     $start = mktime(0, 0, 0, $month, 1, $year);
     $end = mktime(0, 0, 0, $month, date('t', $start), $year);
     $start_week = date('W', $start);
     $end_week = date('W', $end);
  
  if ($end_week &lt; $start_week) { // Month wraps
    return ((52 + $end_week) - $start_week) + 1;
  }
  
  return ($end_week - $start_week) + 1;
  }
  </code></pre>
  
  <p>But this only gives me the number of weeks for that month. </p>