I wouldn't use an absolute number of seconds because of daylight savings time and leapyears/leapseconds. You can let PHP's strtotime()
function take care of this for you by using relative dates. Each iteration through a loop you can simply tell the function to find "Last Monday", and then use that result as your starting point for the next iteration.
The code:
$past_weeks = 7;
$relative_time = time();
$weeks = array();
for($week_count=0;$week_count<$past_weeks;$week_count++) {
$monday = strtotime("last Monday", $relative_time);
$sunday = strtotime("Sunday", $monday);
$weeks[] = array(
date("Y-m-d", $monday),
date("Y-m-d", $sunday),
);
$relative_time = $monday;
}
var_dump($weeks);
The output:
array
0 =>
array
0 => string '2010-09-20' (length=10)
1 => string '2010-09-26' (length=10)
1 =>
array
0 => string '2010-09-13' (length=10)
1 => string '2010-09-19' (length=10)
2 =>
array
0 => string '2010-09-06' (length=10)
1 => string '2010-09-12' (length=10)
3 =>
array
0 => string '2010-08-30' (length=10)
1 => string '2010-09-05' (length=10)
4 =>
array
0 => string '2010-08-23' (length=10)
1 => string '2010-08-29' (length=10)
5 =>
array
0 => string '2010-08-16' (length=10)
1 => string '2010-08-22' (length=10)
6 =>
array
0 => string '2010-08-09' (length=10)
1 => string '2010-08-15' (length=10)