title: Interpolating colors in PHP
body: <p>I'm a C++ programmer who recently started delving into web development with PHP, Javascript and HTML. Currently I'm having trouble with something that should be very simple, but isn't working as I expected...</p>
  
  <pre><code>function interpolateColor($corA, $corB, $lerp)
  {
  $redA = $corA &amp; 0xFF0000;
  $greenA = $corA &amp; 0x00FF00;
  $blueA = $corA &amp; 0x0000FF;
  $redB = $corB &amp; 0xFF0000;
  $greenB = $corB &amp; 0x00FF00;
  $blueB = $corB &amp; 0x0000FF;
  
  $redC = $redA + (($redB - $redA) * $lerp);
  $greenC = $greenA + (($greenB - $greenA) * $lerp);
  $blueC = $blueA + (($blueB - $blueA) * $lerp);
  
  return $redC | $greenC | $blueC;
  }
  </code></pre>
  
  <p>I've been trying to use this function to make the rows of a HTML table different colors based on the value of a "Priority" column, that goes from 0 to 10 and is divided by 10 to form the "lerpAmount" (0-1) variable.</p>
  
  <pre><code>$cor = interpolateColor(0xFF0000, 0x0000FF, $lerpAmount);
  
  &lt;tr bgcolor="&lt;?=$cor?&gt;"&gt;
  </code></pre>
  
  <p>However the colors I get don't look like a Red-Blue interpolation... It starts blueish, then only one of the rows is green, then it becomes pink and interpolates to some form of brown, before turning dark blue again, which makes me think that something's very wrong.</p>
  
  <p>Thanks in advance.</p>