title: PHP - Setting default year in selection box
body: <p>I am new to PHP.  I have a selection box with a range of years starting at current year - 5 (2014) through the year 2050. My selection box contains the correct years but I need it to default to the current year. Right now, it defaults to 2014.  I've been working on this for hours. I thought the $current_year variable was needed in the loop in some way - in order to set the default - but that doesn't work. After researching and seeing various examples, I'm now thinking I need to build an if statement within the loop but I really don't know.  </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form id="calendarForm" name="calendarForm" method="post" action=""&gt;
      &lt;label for="select_year"&gt;Select the year: &lt;/label&gt;
      &lt;select id="select_year" name="select_year"&gt;
          &lt;?php
          $date = new DateTime();
          // Sets the current year
          $current_year = $date-&gt;format('Y');
          // Year to start available options.
          $earliest_year = ($current_year - 5);
          $year = $earliest_year;
  
          for ($year = $earliest_year; $year &lt;= LATEST_YEAR; $year++) {
              echo "&lt;option value='$year'&gt;$year&lt;/option&gt;";
          }
          ?&gt;
  
      &lt;/select&gt;</code></pre>
  </div>
  </div>
  </p>