title: Looking for best way to test when loop changes index
body: <p>Im looking for the best practice to determine when an indexed number inside a loop changes. Take for example this foreach loop which converts the first letter of a word to the ASCII key:</p>
  
  <pre><code>&lt;?php foreach($loterms as $key =&gt; $loterm) : 
  $brand_id = substr($loterm-&gt;name,0,1);
  $index = ord($brand_id);
  endforeach; ?&gt;
  </code></pre>
  
  <p>What I want to know is if the index changes between each run of the loop and if so run some code. For example if the ASCII key changes from 44 to 45 I want to output something different.</p>