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
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.