Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过PHP数组(或对象键)连续循环_Php_Arrays_Object_Foreach_Continuous - Fatal编程技术网

通过PHP数组(或对象键)连续循环

通过PHP数组(或对象键)连续循环,php,arrays,object,foreach,continuous,Php,Arrays,Object,Foreach,Continuous,我有一系列对象键: $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->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_日进行搜索时,显然foreach循环将在找到真正匹配之前停止。如何连续循环数组(或对象键)?我应该把循环放在一个新函数中,并用新的开始日期继续调用它吗?我不想添加额外的数组键->值,因为这会影响以后的事情,我只想在这个函数中添加到初始数组中(这里的示例,数组是为参考而编码的,但是在我的类中-当然是obj键->值,如果你想继续循环,你可以使用

$infinate = new InfiniteIterator(new ArrayIterator($array));
foreach ( $infinate as $value ) {

    // Do your thing
    // Remember to break

}

如果您想连续循环,可以使用

$infinate = new InfiniteIterator(new ArrayIterator($array));
foreach ( $infinate as $value ) {

    // Do your thing
    // Remember to break

}
怎么样

foreach($this->rules->days as $day => $value)
{ 
    if($day == $cur_day)
    {
        $set = true;
    }

    $iii + SECS_PER_DAY;

    if($found_today == true && $value = true)
    {
        return $iii
    }
                // need to find the current day first!


}
怎么样

foreach($this->rules->days as $day => $value)
{ 
    if($day == $cur_day)
    {
        $set = true;
    }

    $iii + SECS_PER_DAY;

    if($found_today == true && $value = true)
    {
        return $iii
    }
                // need to find the current day first!


}

如果这没有打破任何“堆栈溢出使用条款约定”,我必须说:这真是太棒了!还有你@Baba!太棒了!哈哈,记住要打断评论。现在将测试它!@Nik…这将运行到你的系统时间out@Nick如果我理解你想要什么…你甚至可能不需要数组…严重的是它对数组和对象都有效..参见示例..如果s不违反任何“堆栈溢出使用条款约定”,我必须说:这真是太棒了!还有你@Baba!太棒了!哈哈,记住要打断评论。现在将测试它!@Nik…这将运行到你的系统时间out@Nick如果我了解你想要什么…你甚至可能不需要数组…严重的是它对数组和对象都有效..参见示例..我将其限制为1000个循环非常好,但我正在努力寻找下一个真实的日子,而不是今天。抱歉,只是意识到问题中不清楚!问题更新了。很好,但我正在努力寻找下一个真实的日子,而不是今天。抱歉,只是意识到问题中不清楚!问题更新了。