List all dates within date range in PHP

The function to get all dates which falls under the date range specified (i.e. your start date and end date).
It uses PHP DateTime Class to get the result and tested with PHP 5.3

	function _daterange_days($start_date, $end_date, $format = 'Ymd')
		$begin = new DateTime($start_date);
		$end = new DateTime($end_date);
		$end = $end->modify( '+1 day' );

		$result = array();
		$daterange = new DatePeriod($begin, new DateInterval('P1D'), $end);
		foreach($daterange as $date)
			$result[] = $date->format($format);
		return $result;


	$range_days = _daterange_days('2016-02-01', '2016-06-05');

You can also specify optional format parameter to get desired result.
For example to return date format as MM-DD-YYYY:

	$range_days = _daterange_days('2016-02-01', '2016-06-05', 'm-d-Y');