I am trying to get the number of days from the first date to the second date, and then from the second date to the third date and so on. I have a array like this
$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
);
I want to get the number of days from 2016-02-01 to 2016-03-01, and then from 2016-03-01 to 2016-04-01 and so on, if you notice there are some gaps in the dates as in they do jump for more than 1 month. And I want it in a array like this
array()(
[0] => 0,
[1] => 30,
[2] => 60
//so on ...
)
Here is how I am doing it but I am getting errors like uninitialized string offset and I guess the way I am doing is wrong most probably
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;
}
The dates are in string format, extra information that I forgot to mention is that the days needs to get added, for example if we take just the years
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