Sometimes we need to select month value from drop-down and for that we hardcode the month values in HTML option fields. It is possible to dynamically generate the month values using PHP and we can use those generated month values in HTML select option tag.

You may also read Dynamically generate years in PHP

Here is the example how we can generate month values in PHP technology.

Here is the output when we run the generate_month.php file in browser.

php generate months

In the above screen-shot, the function generate_months() generates 12 months from January to December.

Thanks for reading.

Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.