Looping through Dates in PHP

Hi Experts,

How can I loop in between 2 dates?

For example, I have the following code:
//Loop through DR
        $date = new DateTime();
        $date_from = new DateTime($from); //'2015-08-01'
        $date_to = new DateTime($to); //'2015-08'14'
        $date_optput = '';
        $date_compare = '';
        for ($date = $date_from; $date <= $date_to; $date++):
            $date_optput = $date->format('D-M-y');
            echo $date_optput . '<br>';

Open in new window

However, this crashes my browser, ad I'm guessing because it goes through every millisecond? Which is what I don't want.

In comments I added my test data, so I am expecting the following output

Open in new window

Any help will be appreciated.
APD TorontoSoftware DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Maybe someone else could be more helpful, but does this look like what you're trying to do?
Julian HansenCommented:
This should do what you want
$from = '2015-07-01';
$to = '2015-07-31';
$dateFrom = new DateTime($from);
$dateTo = new DateTime($to);
$dateInterval = new DateInterval('P1D');
while($dateFrom <= $dateTo) {
	echo $dateFrom->format('Y-m-d') . '<br/>';

Open in new window

Sample here

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.