I am tryig to get dates between from and to date. By using the datetime class it works fine however when I use it with dynamic result, such as foreach inside foreach the dates is being doubled. I have tried using unique_array but with no luck. Any suggestions? :)
Availabledates content screenshot (ignore the comma):
Example:
$result = $wpdb->get_results('SELECT fdate, tdate FROM availabledates');
foreach($result as $data):
$fdate = date('Y-m-d', $data->fdate);
$tdate = date('Y-m-d', $data->tdate);
$begin = new DateTime($fdate);
$end = new DateTime($tdate);
$daterange = new DatePeriod($begin, new DateInterval('P1D'), $end);
foreach($daterange as $date){
echo $date->format("Y-m-d") . "<br>";
}
endforeach;