mcmuney Posted September 12, 2008 Share Posted September 12, 2008 Below is a portion of code that's displaying years from 1900 to current year on a drop down, starting from 1900. What i'd like to do is reverse the order to show current year first. How can I do that? $start_year="1900"; $end_year=date("Y"); $years=array(); for($i=$start_year; $i<=$end_year; $i++) { $years[]=$i; } Quote Link to comment https://forums.phpfreaks.com/topic/123850-drop-down/ Share on other sites More sharing options...
Maq Posted September 12, 2008 Share Posted September 12, 2008 array_revere(); Quote Link to comment https://forums.phpfreaks.com/topic/123850-drop-down/#findComment-639491 Share on other sites More sharing options...
mcmuney Posted September 13, 2008 Author Share Posted September 13, 2008 I tried array_reverse(), but it didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/123850-drop-down/#findComment-640223 Share on other sites More sharing options...
DarkWater Posted September 13, 2008 Share Posted September 13, 2008 That for loop is unnecessary. <?php $start_year = 1900; $end_year = date('Y); $years = array_reverse(range($start_year, $end_year)); Quote Link to comment https://forums.phpfreaks.com/topic/123850-drop-down/#findComment-640224 Share on other sites More sharing options...
mcmuney Posted September 13, 2008 Author Share Posted September 13, 2008 Worked like a charm... thanks Quote Link to comment https://forums.phpfreaks.com/topic/123850-drop-down/#findComment-640252 Share on other sites More sharing options...
DarkWater Posted September 13, 2008 Share Posted September 13, 2008 Please mark this topic as solved. Quote Link to comment https://forums.phpfreaks.com/topic/123850-drop-down/#findComment-640257 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.