Friday, 3 June 2016

PHP Month full names dropdown

<?php
$monthArray = range(1, 12);
?>
<select name="month">
    <option value="">Select Month</option>
 <?php  
    foreach ($monthArray as $month) {
        // padding the month with extra zero
        $monthPadding = str_pad($month, 2, "0", STR_PAD_LEFT);
        // you can use whatever year you want
        // you can use 'M' or 'F' as per your month formatting preference
        $fdate = date("F", strtotime("2015-$monthPadding-01"));
        echo '<option value="'.$monthPadding.'">'.$fdate.'</option>';
    }
?>  
</select>

1 comment: