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>