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! Quote Link to comment 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>' } } } Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
lonewolf217 Posted May 29, 2009 Share Posted May 29, 2009 <?php foreach($timeOfDay as $amOrPm) { Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.