hoopplaya4 Posted May 29, 2009 Share Posted May 29, 2009 Hi All, I'm creating a calendar and when a user adds an event, they have the ability to select (from a <select> box) a start time and select from another box an end time. I have one quick question: 1) What is the easiest way to code in the values in fifteen minute incrementals? In other words, instead of doing the following: <select> <option value="12am">12:00 AM</option> <option value="12:15am">12:15 AM</option> <option value="12:30am">12:30 AM</option> <option value="12:45am">12:45 AM</option> ... so on How could I use PHP to take up less space? Thanks! Link to comment https://forums.phpfreaks.com/topic/160204-best-way-to-format-times/ Share on other sites More sharing options...
GingerRobot Posted May 29, 2009 Share Posted May 29, 2009 Use hours an minutes: $hours = range(1,11); $hours = array_unshift($times,12); $timeOfDay = array('am','pm'): $minutes = array(15,30,45); foreach($timeOfDay =>$amOrPm){ foreach($hours as $hour){ echo '<option value="' . $hour . $amOrPm .'"> ' . $hour . ':00' . $amOrPm .' </option>' foreach($minutes as $minute){ echo '<option value="' . $hour . ':'. $minute . $amOrPm .'"> ' . $hour . ':'. $minute . $amOrPm .' </option>' } } } Link to comment https://forums.phpfreaks.com/topic/160204-best-way-to-format-times/#findComment-845294 Share on other sites More sharing options...
hoopplaya4 Posted May 29, 2009 Author Share Posted May 29, 2009 Thanks for the help, however, I am getting the following error: Parse error: syntax error, unexpected T_DOUBLE_ARROW Line 33 [referring to the line: foreach ($timeOfDay => $amOrPm) ] Any ideas? Link to comment https://forums.phpfreaks.com/topic/160204-best-way-to-format-times/#findComment-845307 Share on other sites More sharing options...
lonewolf217 Posted May 29, 2009 Share Posted May 29, 2009 <?php foreach($timeOfDay as $amOrPm) { Link to comment https://forums.phpfreaks.com/topic/160204-best-way-to-format-times/#findComment-845310 Share on other sites More sharing options...
GingerRobot Posted May 29, 2009 Share Posted May 29, 2009 I guess that's what you get for trying to write code after having far too much beer in the afternoon :s Ah well, im still glad my exams are (almost) over. Link to comment https://forums.phpfreaks.com/topic/160204-best-way-to-format-times/#findComment-845313 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.