3v4l.org

run code in 300+ PHP versions simultaneously
<?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; } echo year_select("hi",2003,NULL,2006);
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.37, 5.6.0 - 5.6.23, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
<select name='hi' ><option>Select</option><option value='2014' >2014</option><option value='2013' >2013</option><option value='2012' >2012</option><option value='2011' >2011</option><option value='2010' >2010</option><option value='2009' >2009</option><option value='2008' >2008</option><option value='2007' >2007</option><option value='2006' selected='selected' >2006</option><option value='2005' >2005</option><option value='2004' >2004</option><option value='2003' >2003</option></select>

preferences:
226.5 ms | 406 KiB | 350 Q