Needs to be padded to this: str_pad($Month, 2, ‘0’, STR_PAD_LEFT) but how/where???
/*******creates the month selection dropdown array****/ function createMonths($id='month_select', $selected=null) { /*** array of months ***/ $months = array( 1=>'Jan', 2=>'Feb', 3=>'Mar', 4=>'Apr', 5=>'May', 6=>'Jun', 7=>'Jul', 8=>'Aug', 9=>'Sep', 10=>'Oct', 11=>'Nov', 12=>'Dec'); /*** current month ***/ $selected = is_null($selected) ? date('m') : $selected; $select = '<select name=''.$id.'' id=''.$id.''>'.'\n'; foreach($months as $key=>$mon) { $select .= '<option value=\'$key\''; $select .= ($key==$selected) ? ' selected='selected'' : ''; $select .= '>$mon</option>\n'; } $select .= '</select>'; return $select; } /********displays the month selection with current month selected/*******</br> echo createMonths('Month', date ('m')); /******DISPLAYS MONTH AS (4) INSTEAD OF REQUIRED (O4) --- @:( /*****</br> echo $_POST['Month'];
Well, assuming it’s the value you want to be padded, it’s here:
becomes
This assumes that you don’t want it padded when you’re doing the check against
$selected, if you do, you need to do it at the beginning of the loop, overwriting the value in$key, and then you can use your original code, like so: