I am trying this code:

```
$start_date = "2015-08-19";
$end_date = "2016-02-19";
$begin = new DateTime( $start_date );
$end = new DateTime( $end_date);
$interval = new DateInterval('P1Y'); // 1 Year interval

$period = new DatePeriod($begin, $interval, $end);
foreach ( $period as $dt ){
    echo $dt->format( "Y" );
}
$intervals = new DateInterval('P1M'); // 1 month interval

$periods = new DatePeriod($begin, $intervals, $end);
foreach ( $periods as $dts ){
    echo $dts->format( "m" );
}

```

I'm getting output like this:

```
year:2015
Month:08,09,...,01

```

In this output I'm not getting year:2016 and month:02. I want my output like this: 

```
year:2015,2016
Month:08,09,...,01,02

```

How can I get this?

And if my end date is "2016-08-20"

than i m getting year:2016 but not getting month :08

Note that my start date and end date is not fixed.