for ($i = 0; $i <= 4; $i++)
{
$weeks[] = date('m/d/Y', strtotime("-$i week", time()));
}
给出:
array
0 => string '04/23/2012' (length=10)
1 => string '04/16/2012' (length=10)
2 => string '04/09/2012' (length=10)
3 => string '04/02/2012' (length=10)
4 => string '03/26/2012' (length=10)
编辑:如果您想要范围,请执行以下操作:
for ($i = 0; $i <= 4; $i++)
{
$k = $i - 1;
$weeks[] = date('m/d/Y', strtotime("-$i week")) . ' - ' .
date('m/d/Y', strtotime("-$k week -1 day"));
}
给出:
array
0 => string '04/23/2012 - 04/29/2012' (length=23)
1 => string '04/16/2012 - 04/22/2012' (length=23)
2 => string '04/09/2012 - 04/15/2012' (length=23)
3 => string '04/02/2012 - 04/08/2012' (length=23)
4 => string '03/26/2012 - 04/01/2012' (length=23)