Create month and year dropdown list using php

0

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.

If you have any other tricks or suggestion to optimize this code please share with us.

Share.
 

About Author

Entrepreneur & Dreamer

I am a passionate Software Professional, love to learn and share my knowledge with others.

Software is the hardware of my life.

Leave A Reply

CommentLuv badge

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.