在给定的时间范围内每周五,周六和周日

1 php date

在不使用PHP5.0的datetime对象的情况下,在两个日期之间获取每个星期五,星期六和星期日的简单方法是什么.

由于速度我不想在1/1和31/12之间遍历每个日期.(作为结果视图的一部分,每页我必须计算至少50次:).

use*_*291 14

$start = strtotime("today"); // your start/end dates here
$end = strtotime("today + 1 years");

$friday = strtotime("friday", $start);
while($friday <= $end) {
    echo "fri=", date("d m Y", $friday), "\n";
    echo "sat=", date("d m Y", strtotime("+1 days", $friday)), "\n";    
    echo "sun=", date("d m Y", strtotime("+2 days", $friday)), "\n\n";    
    $friday = strtotime("+1 weeks", $friday);
} 
Run Code Online (Sandbox Code Playgroud)

肯定可以优化,但你明白了