Auto Populate Years Range In PHP

by Hiroshi on August 7, 2008

in Form, Useful Scripts

In forms its better approach to populate years drop down list rather then writing down every year manually. This script will ask you starting year and rest of years up till latest year it will populate for you.

<?php
$currentYear = date("Y");
$years = range ($currentYear, 1900);
echo '<select>';
foreach ($years as $value) {
echo "<option value=\"$value\">$value</option>\n";
}
echo '</select>';
?>

Download Script

Related Posts

Previous post:

Next post: