PHP获取本周所有日期
2021-05-04 08:28
标签:function print for code str int format array UNC PHP获取本周所有日期 标签:function print for code str int format array UNC 原文地址:https://www.cnblogs.com/2ger/p/12115200.html获取本周所有日期:
/**
* 获取本周所有日期
*/
function
get_week(
$time
=
‘‘
,
$format
=
‘Y-m-d‘
){
$time
=
$time
!=
‘‘
?
$time
: time();
//获取当前周几
$week
=
date
(
‘w‘
,
$time
);
$date
= [];
for
(
$i
=1;
$i
$i
++){
$date
[
$i
] =
date
(
$format
,
strtotime
(
‘+‘
.
$i
-
$week
.
‘ days‘
,
$time
));
}
return
$date
;
}
执行结果:
print_r(get_week());
Array
(
[1] => 2018-06-18
[2] => 2018-06-19
[3] => 2018-06-20
[4] => 2018-06-21
[5] => 2018-06-22
[6] => 2018-06-23
[7] => 2018-06-24
)
上一篇:获取JS下拉列表中的值