返回strtotime“”之间的所有天数;现在“;以及“+2周”;


Return all days in between strtotime "now" and "+2 weeks"

如何返回两个strtotime函数之间的所有天数?我确信我需要一个foreach循环,但不确定如何进行。

        echo date("jS F, Y", strtotime("now")); 
        echo "<br />";
        echo date("jS F, Y", strtotime("+2 weeks"));

使用DatePeriod迭代器类。文档示例:

$begin = new DateTime( '2007-12-31' );
$end = new DateTime( '2009-12-31 23:59:59' );
$interval = DateInterval::createFromDateString('last thursday of next month');
$period = new DatePeriod($begin, $interval, $end, DatePeriod::EXCLUDE_START_DATE);
foreach ( $period as $dt ) {
  echo $dt->format( "l Y-m-d H:i:s'n" );
}

基本思想。。

<?php
for ($i = 1; $i <= 14; $i++) {
    echo date("jS F, Y", strtotime("now + $i day")); 
        echo "<br />";
}
?>