PHP 使用数组中回两个日期之间的所有日期
要返回两个日期之间的所有日期,代码如下-
示例
<?php
function displayDates($date1, $date2, $format = 'd-m-Y' ) {
$dates = array();
$current = strtotime($date1);
$date2 = strtotime($date2);
$stepVal = '+1 day';
while( $current <= $date2 ) {
$dates[] = date($format, $current);
$current = strtotime($stepVal, $current);
}
return $dates;
}
$date = displayDates('2019-11-10', '2019-11-20');
var_dump($date);
?>输出结果
array(11) {
[0]=>
string(10) "10-11-2019"
[1]=>
string(10) "11-11-2019"
[2]=>
string(10) "12-11-2019"
[3]=>
string(10) "13-11-2019"
[4]=>
string(10) "14-11-2019"
[5]=>
string(10) "15-11-2019"
[6]=>
string(10) "16-11-2019"
[7]=>
string(10) "17-11-2019"
[8]=>
string(10) "18-11-2019"
[9]=>
string(10) "19-11-2019"
[10]=>
string(10) "20-11-2019"
}热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短