我试图获取从第一个日期到第二个日期的天数,然后从第二个日期到第三个日期,依此类推.
我有这样的数组
$dates = array(
2016 - 02 - 01,
2016 - 03 - 01,
2016 - 04 - 01,
2016 - 05 - 01,
2016 - 06 - 01,
2016 - 07 - 01,
2016 - 09 - 01,
2016 - 11 - 01,
2016 - 12 - 01,
2017 - 01 - 01,
2017 - 12 - 01
);
我想知道从2016-02-01到2016-03-01,然后从2016-03-01到2016-04-01的天数等等,如果您注意到日期中存在一些差距他们跳了超过1个月.
我希望它在这样的数组中
array()(
[0] => 0,
[1] => 30,
[2] => 60
//so on ...
)
这是我如何做到这一点,但我得到的错误,如未初始化的字符串偏移,我想我的方式是错误的最可能
public function rangeDates()
{
$dates = array(
'2016-02-01',
'2016-03-01',
'2016-04-01',
'2016-05-01',
'2016-06-01',
'2016-07-01',
'2016-09-01',
'2016-11-01',
'2016-12-01',
'2017-01-01',
'2017-12-01'
);
$datez = array();
$index = 0;
$indexone = 1;
foreach($dates as $date)
{
$datez = round(abs(strtotime($date[$index]) - strtotime($date[$indexone])) / 86400);
$index++;
$indexone++;
}
echo $datez;
}
日期是字符串格式,我忘了提到的额外信息是需要添加的日子,例如,如果我们只需要几年
array(11) (
[0] => (int) 0
[1] => (int) 365
[2] => (int) 730
[3] => (int) 1095
[4] => (int) 1460
[5] => (int) 1825
[6] => (int) 2190
[7] => (int) 2555
[8] => (int) 2920
[9] => (int) 3285
[10] => (int) 3650