Right now my program echo an array of dates generated with for loop. What I'm trying to do is echo dates individually.
Initial code
// initialize an array with your first date
$dates = array(strtotime("+11 days", strtotime("2017-09-04")));
for ($i = 1; $i <= 5; $i++) {// loop 5 times to get the next 5 dates
// add 7 days to previous date in the array
$dates[] = strtotime("+7 days", $dates[$i-1]);
}
// echo the results
foreach ($dates as $date) {
echo date("Y-m-d", $date);
echo "<br>";
}
Initial Output
2017-09-15
2017-09-22
2017-09-29
2017-10-06
2017-10-13
What I have tried
echo $dates[0];//print first date
echo "<br>";
echo $dates[1];//print second date
Trial Output
1505426400
1506031200
How can I achieve this?
date("Y-m-d", $date);or do that on outputforeach ($dates as &$date), note the&), or convert from timestamp to a datestring when you output the values,echo date("Y-m-d", $dates[0]);