Tuesday, 7 October 2014

PHP display 01 instead of 1


<?php
$month = 9;
$year = date('Y');
$select_month_control = '<select name="month" id="month">'; 
for($x = 1; $x <= 12; $x++) { 
$select_month_control.= '<option value="'.str_pad($x, 2, "0", STR_PAD_LEFT).'"'.($x != $month ? '' : ' selected="selected"').'>'.date('F',mktime(0,0,0,$x,1,$year)).'</option>'; 
} $select_month_control.= '</select>';
?>

Output:
<select id="month" name="month">
<option value="01">January</option> <option value="02">February</option> <option value="03">March</option> <option value="04">April</option> <option value="05">May</option> <option value="06">June</option> <option value="07">July</option> <option value="08">August</option> <option selected="selected" value="09">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select>

0 comments:

Post a Comment