是否可以对复杂的 for 循环进行排序?我会将值存储在数组中然后按此排序吗?
这是我正在使用的 for 循环,我想按我正在处理的事件的日期和时间进行排序
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;