Make a dynamic year dropdown using PHP

Ever wanted to have a dropdown that automatically showed the current year and the few years before it?

This is a quick and easy way to do exactly that!

<select name="year"> <?php for($i=date("Y")-5;$i<=date("Y");$i++) { $sel = ($i == date('Y')) ? 'selected' : ''; echo "<option value=".$i." ".$sel."-->".date("Y", mktime(0,0,0,0,1,$i)).""; } ?> </select>
Code language: HTML, XML (xml)
Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments