1

I'm trying to get the date of every Monday in a month. I previously did this for every first Monday and it worked.

$date = strtotime("second monday of $month[$i] $year[j]");

But this didn't work for every monday

$date = strtotime("every monday of $month [$i] $year[j]");

I'm getting the month and year from an array.

4

1 回答 1

6

Why don't you get first monday, and do a loop adding 7 days to it until it is next year?

$first = strtotime("first monday of $year[$j]");
$lastday = mktime(0, 0, 0, 12, 31, $year[$j]);

$day = $first;
do {
    echo date('M d, Y', $day);
    $day += 7 * 86400;

} while ($day < $lastday);
于 2012-09-23T17:52:06.387 回答