- date: documentation ( source)
<?php
function year_select($name,$start_year,$end_year=NULL,$selected_year=NULL,$html_attrs=array()){
$end_year = (isset($end_year))? $end_year : date('Y');
$html_attributes = "";
if(count($html_attrs)>0)
{
foreach($html_attrs as $attr=>$val){
$html_attributes.=" $attr='$val'";
}
}
$select = "<select name='$name' $html_attributes><option>Select</option>";
for($i=$end_year;$i>=$start_year;$i--)
{
$selected=(isset($selected_year) && $selected_year==$i)? " selected='selected' " : "";
$select.="<option value='$i' $selected>$i</option>";
}
$select.="</select>";
return $select;
}
year_select("hi",2003);