title: change row colour in a loop based on value
body: <p>I wish to change tr background colour based on value in a loop so if the value is X for next a few records then colour should be blue, if the value is changed to something else then colour should also be changed to yellow.</p>
  
  <p>My code below is faulty which makes all the rows yellow after painting first one as blue.</p>
  
  <pre><code>foreach ($arr as $key =&gt; $value)
  {
    if ($old_value == $value)
    {
      $colour = 'blue';
    }
    else
    {
      $colour = 'yellow';
      $old_value = $value;
    }
  
  }
  </code></pre>
  
  <p>I need output like this:
  <img src="https://i.stack.imgur.com/teBns.png" alt="enter image description here"></p>