在第三个星期六的日期提取期间出错

Vir*_*oot 1 php arrays date

我想获取第三个星期六,我正在使用PHP功能,我知道.但是从错误中获取时我收到的数据错误.这是我的代码:

$frmdate = 2015-06-05;
$todate = 2015-08-31;

for ($date = strtotime($frmdate); $date <= strtotime($todate); $date = strtotime("+1 day", $date)) 
        {
            $custom_day = date("Y-m-d", $date);

            $custom_third_sat[] = date('Y-m-d', strtotime('third Saturday "'.$custom_day.'"'));

        }
        echo "<pre>";
        print_r($custom_third_sat);
Run Code Online (Sandbox Code Playgroud)

我哪里错了?

小智 6

每个月只包含一个"第三个星期六",所以不需要做更多的循环.试试这段代码一次.

$frmdate = "2015-06-05";
$todate = "2015-08-31";
$custom_third_sat=array();
for ($date = date("Y-m-01", strtotime($frmdate)); $date <= $todate; $date = date("Y-m-01",strtotime($date."+1 Month"))) {
    if($date>$todate){
        break;
    }
    $t_date=date('Y-m-d', strtotime($date.' third Saturday'));
    if($t_date>=$frmdate && $t_date<=$todate)
    {
        $custom_third_sat[] = $t_date;
    }

}
echo "<pre>";print_r($custom_third_sat);
Run Code Online (Sandbox Code Playgroud)