Q:

php dropdown - show current year starting from 2017

<?php

echo '<select name="fromYear"';
 $starting_year  =date('Y', strtotime('-1 year'));
$current_year = date('Y');
 $ending_year = date('Y', strtotime('+10 year'));

 for($starting_year; $starting_year <= $ending_year; $starting_year++) {
     echo '<option value="'.$starting_year.'"';
     if( $starting_year ==  $current_year ) {
            echo ' selected="selected"';
     }
     echo ' >'.$starting_year.'</option>';
 }               
 echo '<select>';
?>

Hi i have this code how to modify this..to show current year and previous year starting from 2017
starting year : 2017
when in 2017 : i will only see 2017 in drop down
2018 : 2017, 2018
2019 : 2017, 2018, 2019
2020 : 2017, 2018, 2019, 2020
and so on...

A:

Use do while to start for the current year as follows: 
<?php
    $starting_year = 2017;
    $current_year = date('Y')*1;
    echo '<select name="years">';
    echo '<option>Select</option>';
    do {
        echo '<option value="'.$starting_year.'">'.$starting_year.'</option>';
        $starting_year++;
    }
    while ($current_year >= $starting_year);
    echo '</select>';

    ?>

Online Demo
From PHP official documentation: 

do-while loops are very similar to while loops, except the truth
  expression is checked at the end of each iteration instead of in the
  beginning. The main difference from regular while loops is that the
  first iteration of a do-while loop is guaranteed to run (the truth
  expression is only checked at the end of the iteration), whereas it
  may not necessarily run with a regular while loop...

