title: How to condense a large battery of conditions into a lookup array?
body: <p>I am trying to write a function that looks up an <code>$InterestRate</code> value for insurance payments on a car. I have inserted the table below the code:</p>
  <p>Currently I have tried:</p>
  <pre><code>function interestRate() {
  if ((int)$VehicleYear &gt;= 2001) &amp;&amp; (int)$VehicleYear &lt;= 2005){
  
      $Term = 24;
  
      if ((int)$CreditScore &gt;= 720){
          $InterestRate = 15.90;
      }
      elseif ((int)$CreditScore &gt;= 610) || ((int)$CreditScore &lt;= 719) {
          $InterestRate = 19.90;
      }
      elseif ((int)$CreditScore &gt;= 580) || ((int)$CreditScore &lt;= 609) {
          $InterestRate = 22.90;
      }
      elseif ((int)$CreditScore &gt;= 530) || ((int)$CreditScore &lt;= 579) {
          $InterestRate = 22.90;
      }
      elseif ((int)$CreditScore &gt;= 489) || ((int)$CreditScore &lt;= 529) {
          $InterestRate = 22.90;
      }
  }
  
  if ((int)$VehicleYear == 2006){
  
      $Term = 24;
  
      if ((int)$CreditScore &gt;= 720){
          $InterestRate = 15.90;
      }
      elseif ((int)$CreditScore &gt;= 610) || ((int)$CreditScore &lt;= 719) {
          $InterestRate = 18.90;
      }
      elseif ((int)$CreditScore &gt;= 580) || ((int)$CreditScore &lt;= 609) {
          $InterestRate = 21.90;
      }
      elseif ((int)$CreditScore &gt;= 530) || ((int)$CreditScore &lt;= 579) {
          $InterestRate = 22.90;
      }
      elseif ((int)$CreditScore &gt;= 489) || ((int)$CreditScore &lt;= 529) {
          $InterestRate = 22.90;
      }
  }
  if ((int)$VehicleYear == 2007){
  
      $Term = 36;
  
      if ((int)$CreditScore &gt;= 720){
          $InterestRate = 15.90;
      }
      elseif ((int)$CreditScore &gt;= 610) || ((int)$CreditScore &lt;= 719) {
          $InterestRate = 18.90;
      }
      elseif ((int)$CreditScore &gt;= 580) || ((int)$CreditScore &lt;= 609) {
          $InterestRate = 21.90;
      }
      elseif ((int)$CreditScore &gt;= 530) || ((int)$CreditScore &lt;= 579) {
          $InterestRate = 22.90;
      }
      elseif ((int)$CreditScore &gt;= 489) || ((int)$CreditScore &lt;= 529) {
          $InterestRate = 22.90;
      }
  }
  if ((int)$VehicleYear == 2008){
  
      $Term = 36;
  
      if ((int)$CreditScore &gt;= 720){
          $InterestRate = 14.90;
      }
      elseif ((int)$CreditScore &gt;= 610) || ((int)$CreditScore &lt;= 719) {
          $InterestRate = 17.90;
      }
      elseif ((int)$CreditScore &gt;= 580) || ((int)$CreditScore &lt;= 609) {
          $InterestRate = 21.90;
      }
      elseif ((int)$CreditScore &gt;= 530) || ((int)$CreditScore &lt;= 579) {
          $InterestRate = 21.90;
      }
      elseif ((int)$CreditScore &gt;= 489) || ((int)$CreditScore &lt;= 529) {
          $InterestRate = 21.90;
      }
  }
  
  if ((int)$VehicleYear == 2009){
  
      $Term = 36;
  
      if ((int)$CreditScore &gt;= 720){
          $InterestRate = 14.90;
      }
      elseif ((int)$CreditScore &gt;= 610) || ((int)$CreditScore &lt;= 719) {
          $InterestRate = 17.90;
      }
      elseif ((int)$CreditScore &gt;= 580) || ((int)$CreditScore &lt;= 609) {
          $InterestRate = 20.90;
      }
      elseif ((int)$CreditScore &gt;= 530) || ((int)$CreditScore &lt;= 579) {
          $InterestRate = 20.90;
      }
      elseif ((int)$CreditScore &gt;= 489) || ((int)$CreditScore &lt;= 529) {
          $InterestRate = 20.90;
      }
  }
  
  if ((int)$VehicleYear == 2010){
  
      $Term = 36;
  
      if ((int)$CreditScore &gt;= 720){
          $InterestRate = 14.90;
      }
      elseif ((int)$CreditScore &gt;= 610) || ((int)$CreditScore &lt;= 719) {
          $InterestRate = 17.90;
      }
      elseif ((int)$CreditScore &gt;= 580) || ((int)$CreditScore &lt;= 609) {
          $InterestRate = 20.90;
      }
      elseif ((int)$CreditScore &gt;= 530) || ((int)$CreditScore &lt;= 579) {
          $InterestRate = 20.90;
      }
      elseif ((int)$CreditScore &gt;= 489) || ((int)$CreditScore &lt;= 529) {
          $InterestRate = 20.90;
      }
  }
  
  if ((int)$VehicleYear == 2011){
  
      $Term = 42;
  
      if ((int)$CreditScore &gt;= 720){
          $InterestRate = 14.90;
      }
      elseif ((int)$CreditScore &gt;= 610) || ((int)$CreditScore &lt;= 719) {
          $InterestRate = 16.90;
      }
      elseif ((int)$CreditScore &gt;= 580) || ((int)$CreditScore &lt;= 609) {
          $InterestRate = 19.90;
      }
      elseif ((int)$CreditScore &gt;= 530) || ((int)$CreditScore &lt;= 579) {
          $InterestRate = 19.90;
      }
      elseif ((int)$CreditScore &gt;= 489) || ((int)$CreditScore &lt;= 529) {
          $InterestRate = 20.90;
      }
  }
  
  if ((int)$VehicleYear == 2012){
  
      $Term = 42;
  
      if ((int)$CreditScore &gt;= 720){
          $InterestRate = 12.90;
      }
      elseif ((int)$CreditScore &gt;= 610) || ((int)$CreditScore &lt;= 719) {
          $InterestRate = 15.90;
      }
      elseif ((int)$CreditScore &gt;= 580) || ((int)$CreditScore &lt;= 609) {
          $InterestRate = 18.90;
      }
      elseif ((int)$CreditScore &gt;= 530) || ((int)$CreditScore &lt;= 579) {
          $InterestRate = 19.90;
      }
      elseif ((int)$CreditScore &gt;= 489) || ((int)$CreditScore &lt;= 529) {
          $InterestRate = 19.90;
      }
  }
  
  if ((int)$VehicleYear == 2013){
  
      $Term = 42;
  
      if ((int)$CreditScore &gt;= 720){
          $InterestRate = 12.90;
      }
      elseif ((int)$CreditScore &gt;= 610) || ((int)$CreditScore &lt;= 719) {
          $InterestRate = 15.90;
      }
      elseif ((int)$CreditScore &gt;= 580) || ((int)$CreditScore &lt;= 609) {
          $InterestRate = 18.90;
      }
      elseif ((int)$CreditScore &gt;= 530) || ((int)$CreditScore &lt;= 579) {
          $InterestRate = 18.90;
      }
      elseif ((int)$CreditScore &gt;= 489) || ((int)$CreditScore &lt;= 529) {
          $InterestRate = 18.90;
      }
  }
  
  if ((int)$VehicleYear &gt;= 2014){
  
      $Term = 48;
  
      if ((int)$CreditScore &gt;= 720){
          $InterestRate = 11.90;
      }
      elseif ((int)$CreditScore &gt;= 610) || ((int)$CreditScore &lt;= 719) {
          $InterestRate = 14.90;
      }
      elseif ((int)$CreditScore &gt;= 580) || ((int)$CreditScore &lt;= 609) {
          $InterestRate = 17.90;
      }
      elseif ((int)$CreditScore &gt;= 530) || ((int)$CreditScore &lt;= 579) {
          $InterestRate = 18.90;
      }
      elseif ((int)$CreditScore &gt;= 489) || ((int)$CreditScore &lt;= 529) {
          $InterestRate = 18.90;
      }
  }
  }
  </code></pre>
  <p>It is both tedious and simply does not work when I try to use <code>$InterestRate</code> in a calculation. What is the best way to approach this one?</p>
  <p><strong>EDIT</strong> : Some have mentioned using an SQL table. I have no idea how to do that. But here is my table basically</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;table style="undefined;table-layout: fixed; width: 497px"&gt;
  &lt;colgroup&gt;
  &lt;col style="width: 93px"&gt;
  &lt;col style="width: 73px"&gt;
  &lt;col style="width: 75px"&gt;
  &lt;col style="width: 64px"&gt;
  &lt;col style="width: 64px"&gt;
  &lt;col style="width: 64px"&gt;
  &lt;col style="width: 64px"&gt;
  &lt;/colgroup&gt;
    &lt;tr&gt;
      &lt;th&gt;Vehicle Year&lt;/th&gt;
      &lt;th&gt;Term&lt;/th&gt;
      &lt;th&gt;FICO&lt;/th&gt;
      &lt;th&gt;FICO&lt;/th&gt;
      &lt;th&gt;FICO&lt;/th&gt;
      &lt;th&gt;FICO&lt;/th&gt;
      &lt;th&gt;FICO&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;/td&gt;
      &lt;td&gt;&lt;/td&gt;
      &lt;td&gt;720 +&lt;/td&gt;
      &lt;td&gt;719-610&lt;/td&gt;
      &lt;td&gt;609-580&lt;/td&gt;
      &lt;td&gt;579-530&lt;/td&gt;
      &lt;td&gt;529-489&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2014-current&lt;/td&gt;
      &lt;td&gt;48&lt;/td&gt;
      &lt;td&gt;11&lt;/td&gt;
      &lt;td&gt;14&lt;/td&gt;
      &lt;td&gt;17&lt;/td&gt;
      &lt;td&gt;18&lt;/td&gt;
      &lt;td&gt;18&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2013&lt;/td&gt;
      &lt;td&gt;42&lt;/td&gt;
      &lt;td&gt;12&lt;/td&gt;
      &lt;td&gt;15&lt;/td&gt;
      &lt;td&gt;18&lt;/td&gt;
      &lt;td&gt;18&lt;/td&gt;
      &lt;td&gt;18&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2012&lt;/td&gt;
      &lt;td&gt;42&lt;/td&gt;
      &lt;td&gt;12&lt;/td&gt;
      &lt;td&gt;15&lt;/td&gt;
      &lt;td&gt;18&lt;/td&gt;
      &lt;td&gt;19&lt;/td&gt;
      &lt;td&gt;19&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2011&lt;/td&gt;
      &lt;td&gt;42&lt;/td&gt;
      &lt;td&gt;14&lt;/td&gt;
      &lt;td&gt;16&lt;/td&gt;
      &lt;td&gt;19&lt;/td&gt;
      &lt;td&gt;19&lt;/td&gt;
      &lt;td&gt;20&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2010&lt;/td&gt;
      &lt;td&gt;36&lt;/td&gt;
      &lt;td&gt;14&lt;/td&gt;
      &lt;td&gt;17&lt;/td&gt;
      &lt;td&gt;20&lt;/td&gt;
      &lt;td&gt;20&lt;/td&gt;
      &lt;td&gt;20&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2009&lt;/td&gt;
      &lt;td&gt;36&lt;/td&gt;
      &lt;td&gt;14&lt;/td&gt;
      &lt;td&gt;17&lt;/td&gt;
      &lt;td&gt;20&lt;/td&gt;
      &lt;td&gt;20&lt;/td&gt;
      &lt;td&gt;20&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2008&lt;/td&gt;
      &lt;td&gt;36&lt;/td&gt;
      &lt;td&gt;14&lt;/td&gt;
      &lt;td&gt;17&lt;/td&gt;
      &lt;td&gt;21&lt;/td&gt;
      &lt;td&gt;21&lt;/td&gt;
      &lt;td&gt;21&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2007&lt;/td&gt;
      &lt;td&gt;36&lt;/td&gt;
      &lt;td&gt;15&lt;/td&gt;
      &lt;td&gt;18&lt;/td&gt;
      &lt;td&gt;21&lt;/td&gt;
      &lt;td&gt;22&lt;/td&gt;
      &lt;td&gt;21&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2006&lt;/td&gt;
      &lt;td&gt;24&lt;/td&gt;
      &lt;td&gt;15&lt;/td&gt;
      &lt;td&gt;18&lt;/td&gt;
      &lt;td&gt;21&lt;/td&gt;
      &lt;td&gt;22&lt;/td&gt;
      &lt;td&gt;22&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;2001-2005&lt;/td&gt;
      &lt;td&gt;24&lt;/td&gt;
      &lt;td&gt;15&lt;/td&gt;
      &lt;td&gt;19&lt;/td&gt;
      &lt;td&gt;22&lt;/td&gt;
      &lt;td&gt;22&lt;/td&gt;
      &lt;td&gt;22&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  Extra o</code></pre>
  </div>
  </div>
  </p>