avp Posted January 24, 2017 Share Posted January 24, 2017 How do I reverse the order of the year display in this code for a select dropdown list? <select required name="year" id="year"> <option value="" selected="selected"><span style="font-family: 'Open Sans', sans-serif;">Select Year:</span></option> <?php $y = Date('Y'); for ($i=$y-11; $i < $y+2; $i++) { echo '<option value="' . $i . '">' . $i . '</option>' . "\n"; } ?> </select> Quote Link to comment Share on other sites More sharing options...
Barand Posted January 24, 2017 Share Posted January 24, 2017 for ($i=$y+1; $i >= $y-11; $i--) Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted January 24, 2017 Share Posted January 24, 2017 Alternate solution: <?php $y = date('Y'); $yearRange = range($y+1, $y-11); foreach($yearRange as $currYear) { echo '<option value="' . $currYear . '">' . $currYear . '</option>' . "\n"; } ?> Quote Link to comment 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.