i have an app where i save weekdays and business hours on MySql as follow:
0 10 22,1 10 22,2 10 22,4 10 22,5 10 22,6 10 22
The php array fetch this from Mysql as following formats
Array ( [open_hours] => 0 10 22,1 10 22,2 10 22,4 10 22,5 10 22,6 10 22 )
0 10 22 simply means Monday 10am 22pm
My current code seems not works well, below are the code i use to format the date and time
$openHrs = $businessMapper->getBusinessHours($business_id);
// return Array ( [open_hours] => 0 10 22,1 10 22,2 10 22,4 10 22,5 10 22,6 10 22 )
$openHrs = explode(",", $openHrs['open_hours']);
$weekdays = array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
foreach($openHrs as &$temp) {
//$temp = $weekdays[$temp[0]]
$temp = explode(" ", $temp);
//$temp = explode(" ", $temp);
$temp[1] = $temp[1] > 12 ? $temp[1] - 12 . 'pm' : $temp[1] . 'am';
$temp[2] = $temp[2] > 12 ? $temp[2] - 12 . 'pm' : $temp[2] . 'am';
$temp = $weekdays[$temp[0]] . ' ' . $temp[1] . ' ' . $temp[2];
}
But the issues is, i only get one result which is Sat 10am 10pm. How can i fix my code? Thanks!!