Create month and year dropdown list using php

There are times when you need to create month and year dropdown list dynamically. I have used this code in many of my project’s reporting section. So I am sharing this useful piece of code with all of you.

Create year dropdown list

Creating the year dropdown list is extremely easy. Just give a start and end year range and your year array is created, now just loop it over.

Create month dropdown list

There are two ways you can create the month dropdown list. First one is where you define a php array variable with all the month list and just loop over and display the dropdown. Have a look at the first method below.

The other method is a bit tricky as it relies on php function rather rather than defining static month array.

Related Post

Leave a Reply

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