I am having some trouble with creating this dropdown menu. It comes back with an error Notice: Undefined offset: 2004 in
The date is in the dropdown but not selected. Can some one explain this to me?
Thanks
<?php $t = getdate(time()); $years = array(1 =>'2003', '2004', '2005'); echo "<select name=year >"; echo "<option value=\"" . $t['year'] . "\">" . $years[$t['year']] . "</option>"; foreach( $years as $key => $value ) { echo "<option value = \"$key\">$value</option>"; } echo "</select>"; ?>
In this line:
$years = array(1 =>'2003', '2004', '2005');
you define each year as an array value, but here:
$years[$t['year']]
you attempt to use it as the array index ("offset"), while the actual indexes are "1, 2, 3...".