PHP Looping through dates

后端 未结 1 1142
清酒与你
清酒与你 2021-01-26 12:59

I have the following while loop which compares 2 dates to see if 1 is less than another, and if not then it adds a week to the first date.

It works fine, however where t

相关标签:
1条回答
  • 2021-01-26 13:54

    It looks like you're doing a little more to $startDate than you expect - you're modifying the object with ->startOfWeek() and ->endOfWeek() rather than just calculating the string output; my reading of the source to Carbon is that every method you call modifies the object, so the assignment in the last line of your while loop is unnecessary (it could just as easily be written as $startDate->addDays(7);. As a result of that your code is a little bit less efficient than it could be, and might even loop one or two times more than you want.

    However, I would suspect this block of code isn't your real problem, and that it's further down your codebase - if your problems grow with the size of $data['weeks'] then it's probably something in the way in which you're processing it for your HTML.

    0 讨论(0)
提交回复
热议问题