title: Loop Year and Months
body: <p>How can I loop the year and months with some given dates?
  Below is my current code and I can't get it running</p>
  
  <pre><code>$Startdate = '2017-01';
  $Enddate = '2018-06';
  
   for($selectedDate = date("Y-m",$begin); $selectedDate &lt;= date("Y-m",$end); $selectedDate++){
      $resultY = date("Y",strtotime($selectedDate));
      $resultM = date("m",strtotime($selectedDate));
  
      echo $resultY;
      $echo resulthM;
  }
  </code></pre>
  
  <p>The output should be:</p>
  
  <pre><code>2017    1
  2017    2
  2017    3
  2017    4
  2017    5
  2017    6
  2017    7
  2017    8
  2017    9
  2017    10
  2017    11
  2017    12
  2018    1
  2018    2
  2018    3
  2018    4
  2018    5
  2018    6
  </code></pre>