Michael Michael - 5 months ago 8
PHP Question

How to make PHP for loop to count down instead of up?

I am using PHP to create a dropdown box with years from 1900 to 2012. However, I'd like to have 2012 at the top of the list (i.e. count down from 2012 to 1900 instead of up from 1900 to 2012).

Any help you can provide would be great! :)

<select id="year">
<option value="">----</option>
<?
for ($i = 1900; $i <= 2012; $i++){
echo '<option value="'.$i.'">'.$i.'</option>';
}
?>
</select>

Answer
for($i = 2012; $i >= 1900; $i--)