title: Split the current month in to weeks in php
body: <p>I want to split the current month in to weeks like first day to saturday and then sunday to next saturday.For ex: for May month, So i want to split that like</p>
  
  <pre><code>2016-05-01 to 2016-05-07
  2016-05-08 to 2016-05-14
  2016-05-15 to 2016-05-21
  2016-05-22 to 2016-05-28
  2016-05-29 to 2016-05-31
  </code></pre>
  
  <p>if i try the below code,i didnt get exact result.</p>
  
  <pre><code>&lt;?php
  
  $start_date = date('Y-m-d', strtotime('2016-06-01'));
  $end_date = date('Y-m-d', strtotime('2016-06-30'));
  $i=1;
  for($date = $start_date; $date &lt;= $end_date; $date = date('Y-m-d',       strtotime($date. ' + 7 days'))) {
      echo getWeekDates($date, $start_date, $end_date, $i);
      echo "\n";
      $i++;
  }
  
  function getWeekDates($date, $start_date, $end_date, $i) {
      $week =  date('W', strtotime($date));
      $year =  date('Y', strtotime($date));
  
      $from = date("Y-m-d", strtotime("{$year}-W{$week}+1")); 
      if($from &lt; $start_date) $from = $start_date;
  
      $to = date("Y-m-d", strtotime("{$year}-W{$week}-7"));   
      if($to &gt; $end_date) $to = $end_date;
  
      echo $from." - ".$to.'&lt;br&gt;';    
  }
  
  ?&gt;
  </code></pre>
  
  <p>i got like</p>
  
  <pre><code>2016-05-01 - 2016-05-01
  2016-05-01 - 2016-05-08
  2016-05-08 - 2016-05-15
  2016-05-15 - 2016-05-22
  2016-05-22 - 2016-05-29
  </code></pre>
  
  <p>In for loop, while checking last set of days, conditon get failed .so it doesnt calculate 30,31.</p>
  
  <p>How can i do that? </p>