我正在使用strtotime函数,但我还需要将我的开始日期包含在数组列表中

时间:2016-10-24 02:17:33

标签: while-loop strtotime

我正在使用strtotime函数,但我还需要将我的开始日期包含在数组列表中 这是代码片段

array (
  'startdate' => '2016-10-16',
  'enddate' => '2016-10-16',
)array (
  'startdate' => '2016-10-17',
  'enddate' => '2016-10-17',
)array (
  'startdate' => '2016-10-18',
  'enddate' => '2016-10-18',
)array (
  'startdate' => '2016-10-19',
  'enddate' => '2016-10-19',
)array (
  'startdate' => '2016-10-20',
  'enddate' => '2016-10-20',
)array (
  'startdate' => '2016-10-21',
  'enddate' => '2016-10-21',
)array (
  'startdate' => '2016-10-22',
  'enddate' => '2016-10-22',
)array (
  'startdate' => '2016-10-23',
  'enddate' => '2016-10-23',
)array (
  'startdate' => '2016-10-24',
  'enddate' => '2016-10-24',
)

然后结果是

array (
 'startdate' => '2016-10-15',
       'enddate'   => '2016-10-15'
     (
  'startdate' => '2016-10-16',
  'enddate' => '2016-10-16',
    )array (
      'startdate' => '2016-10-17',
      'enddate' => '2016-10-17',
    )array (
  'startdate' => '2016-10-18',
  'enddate' => '2016-10-18',
)array (
  'startdate' => '2016-10-19',
  'enddate' => '2016-10-19',
)array (
  'startdate' => '2016-10-20',
  'enddate' => '2016-10-20',
)array (
  'startdate' => '2016-10-21',
  'enddate' => '2016-10-21',
)array (
  'startdate' => '2016-10-22',
  'enddate' => '2016-10-22',
)array (
  'startdate' => '2016-10-23',
  'enddate' => '2016-10-23',
)array (
  'startdate' => '2016-10-24',
  'enddate' => '2016-10-24',
)

但我的预期结果是这个

{{1}}

关于此任何想法,谢谢你将感谢任何可用的帮助

1 个答案:

答案 0 :(得分:0)

我认为这就是你要找的东西,所有你要做的就是在计算下一个日期之前移动你:

while (strtotime($startDate) <= strtotime($newEnddate)) { 
    $dates = array(                // moved line
        'startdate' => $startDate, // changed
        'enddate' => $startDate    // changed
    );
    $this->ddc_get_res($dates);    // moved line

    $newStartDate = date ("Y-m-d", strtotime("+1 day", strtotime($startDate)));
    $startDate = $newStartDate;
}