Is it possible to sort a complex for loop? Would I store the values in an array and then sort by that?
This is the for loop I'm working with, I would like to sort by the date & time of the events I'm pulling through
foreach ($recurring_events as $recurring_event):
if ($recurring_event->period == 'week') {
$StartDate = strtotime($event->RequestDateStart);
$EndDate = strtotime($event->RequestDateEnd);
$TotalDays = round(($EndDate-$StartDate)/(60*60*24*7));
for($i=0; $i<($TotalDays-1); $i++) {
$StartDate += (60*60*24*7);
if (date('WMY', $StartDate) == date('WMY')) {
echo '<div class="col-12">';
echo '<strong>Event Name:</strong> ' . $event->EventName . '<br /><strong>Date:</strong> ' . date('l, F j o',$StartDate) . '<br /><strong>Start Time:</strong> ' . date('g:i a',strtotime($event->RequestTimeStart));
echo '</div>';
}
}
}
endforeach;
$recurring_event
supposed to be$event
? – Philip Whitehouse Feb 4 at 23:34$StartDate
is going to be the same every time you go round the loop. – Philip Whitehouse Feb 4 at 23:40