我有一系列对象键:
$this->rules->days->mon = isset($this->recurring_event_data['post_ar'][$this->rules->type]['mon']) ? true : false;
$this->rules->days->tue = isset($this->recurring_event_data['post_ar'][$this->rules->type]['tue']) ? true : false;
$this->rules->days->wed = isset($this->recurring_event_data['post_ar'][$this->rules->type]['wed']) ? true : false;
$this->rules->days->thu = isset($this->recurring_event_data['post_ar'][$this->rules->type]['thu']) ? true : false;
$this->rules->days->fri = isset($this->recurring_event_data['post_ar'][$this->rules->type]['fri']) ? true : false;
$this->rules->days->sat = isset($this->recurring_event_data['post_ar'][$this->rules->type]['sat']) ? true : false;
$this->rules->days->sun = isset($this->recurring_event_data['post_ar'][$this->rules->type]['sun']) ? true : false;
我有这个功能:
function calc_next_weekly_interval($ii,$i)
{
global $array;
// we will roll through this->rules->mon,tue,wed,thu,fri,sat,sun. If its true, return the new iii value, if not keep looping through the array until we hit true again.
$cur_day = strtolower(date('D',$ii));
$found_today = false;
// our initial start date
$iii = $ii;
foreach($this->rules->days as $day => $value)
{
if($found_today == true && $value = true)
{
return $iii
}
// need to find the current day first!
if($day == $cur_day)
{
$found_today = true;
}
$iii + SECS_PER_DAY;
}
}
都好。注意我试图从当天找到下一个真实的日子。问题是当我使用星期日作为初始 cur_day 进行搜索时,显然 foreach 循环将在找到真正匹配之前停止。如何连续循环遍历数组(或对象键)?我应该将循环放在一个新函数中并继续使用新的开始日期调用它吗?我不想添加额外的数组键->值,因为它会影响以后的事情,我考虑过只在这个函数中添加到初始数组(这里的例子,数组被编码以供参考,但在我的类中 - 它当然是 obj 键-> 值