I have an array which is converted to string and it looks like this: 00:00,05:00,10:00,15:00,20:00 it shows hours range every 5 hours,
I want to display my string like this , , , ,5:00, , , , ,10:00, , , , ,15:00, , , , ,20:00, , , ,
so display it every 5 hours but hours that are not needed i want to set empty,
code:
$date = new \DateTime("12:00am");
$dv = new \DateInterval('PT5H');
$totalInterval = 4 ;
$dr = array();
$date->format('H:i');
for($i = 0; $i < $totalInterval; $i++)
{
$dr[] = $date->format('H:i');
$date->add($dv);
}
$dr[] = $date->format('H:i');
$dr = implode (',', $dr);
How would I do that ?
1 Answer