Hugh Lashbrooke

Product manager by day, tabletop game designer by night.

Easily generate a month select box in PHP

Having a drop down menu for month selection is a relatively common need, but it can be a pain to write from scratch each time. Here’s a short snippet that will generate a select input (drop down menu) for all 12 months of the year – the option values will be the month numbers with leading zeros:


View this gist on GitHub

To remove the leading zeros, simply remove the line with the str_pad() function.

2 responses to “Easily generate a month select box in PHP”

  1. Ahsan Khan Avatar
    Ahsan Khan

    Perfect

  2. Hike Avatar
    Hike

    Thanks!

Leave a Reply

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