php function to create date and time dropdown / select boxes

I don’t know about you, but I really do not like building out crazy drop down boxes something about doing a minutes dropdown of 1-60 really annoys me. It got me to thinking how easy would be to write a simple function to do this thinking for me… Now I admit the calendar drop down has pretty much rendered this useless, but think about the progressive enhancement, for the love of no javascript’s sake.
I wanted to make something reusable that can be called across a site to build them out and increment dates/time whenever needed.
The function goes as follows:
public function createDateTimeDropDowns ($params=array()) {$start = isset($params['start']) ? $params['start'] : '00:00:00';$datetime = new DateTime($start);$outputHTML = '<option value=""></option>';for ($i = 0; $i <= $params['limit']; $i ++) {$selected='';$value=$datetime->format($params['formatValue']);if($params['preselected'] == $value){$selected = 'selected';}$outputHTML .= '<option value="'.$value.'" '.$selected.'>'.$datetime->format($params['formatSelect']).'</option>';$datetime->modify($params['steps']);}return $outputHTML;}
You can call the function to make you pretty dropdowns like this:
$selYear=self::createDateTimeDropDowns(array('start'=>date("Y"),'steps'=>
'+1 year','limit'=>1,'formatValue'=>'Y','formatSelect'=>'Y','
preselected'=>$scheduledYear));$selMonth=self::createDateTimeDropDowns(array('start'=>'January','steps'=>
'+1 month','limit'=>11,'formatValue'=>'n','formatSelect'=>'M','
preselected'=>
$scheduledMonth));$selDay=self::createDateTimeDropDowns(array('start'=>'March 1','steps'=>
'+1 day','limit'=>30,'formatValue'=>'j','formatSelect'=>'j','
preselected'=>$scheduledDay));$outputHTML = <<< HTML<div id="scheduler"><label for="scheduler">Time</label><select id="scheduledMonth" name="selMonth">$selMonth</select><select name="scheduledDay" id="scheduledDay">$selDay</select><select name="scheduledYear" id="selYear">$selYear</select></div>HTML;
