hi i have script gives me list of days date between a week. i need the reverse the the order. alredy tried rsort, reverse_array, and much more some how all giving error.
thanks.
script
$date2 = "$lastweek2";
$date1 = "$lastweek1";
$start = new DateTime($date2);
$end = new DateTime($date1);
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($start, $interval, $end);
echo "<br>";
foreach ($period as $dt) {
echo $dt->format("Y-m-d") . "<br>\n";
}
echo is like this
2014-08-09
2014-08-10
2014-08-11
2014-08-12
2014-08-13
2014-08-14
2014-08-15
reversed
2014-08-15
2014-08-14
2014-08-13
2014-08-12
2014-08-11
2014-08-10
2014-08-09
Just put the dates in an array and then reverse the order of the array using array_reverse()
$dates = array();
foreach ($period as $dt) {
$dates[] = $dt->format("Y-m-d");
}
$dates = array_reverse($dates);
echo implode("<br>\n", $dates);