PHP

Create Month Dropdwon Using Date Function In PHP.

There are two ways to create month dropdown in php. First, we can create static array of months and then loop these arrays and create a dropdwon.

But in this post we will learn month dropdown using PHP inbuilt date function.

 
 <select name="month" id="month">
           <option value="">Select Month</option>
            <?php
                      for ($i = 1; $i <= 12; $i++) {
                            $time =   mktime(0, 0, 0, $i); 
                             $label =  date('F', $time);  
                             $value =  date('n', $time);
                          echo "<option value='$value'>$label</option>";
                 }
        ?>
   </select>
DEMO

Related Articles

Check Also
Close
Back to top button