title: Help me combine these conditions for determining if this list item begins with a new letter
body: <p>Maybe I'm having a bad day, but I can't seem to combine these 2 conditions into 1. They obviously should be, because they output the exact same data. The following code creates a list with A-Z to act as anchor links, and is then meant to traverse an array in the format <code>'word'=&gt;'definition'</code>. I wanted the PHP to output a h3 element with the current letter everytime it detected a new letter.</p>
  
  <p>Here is what I have</p>
  
  <pre><code>    $letters = range('A', 'Z');
      echo '&lt;em&gt;Jump to:&lt;/em&gt;&lt;ul class="letters"&gt;';
      // anchors
      foreach ($letters as $letter) {            
          echo '&lt;li&gt;&lt;a href="#botany-words-' . $letter . '"&gt;' . $letter . '&lt;/a&gt;&lt;/li&gt;';      
      }        
      echo '&lt;/ul&gt;';        
      // start listing them!        
      $currentLetter = 0;        
      echo '&lt;dl id="botany-words"&gt;';
  
      foreach($content as $botanyWord=&gt;$definition) {
  
           if ($botanyWord == key(array_slice($content, 0, 1))) { // must be first, aka 'A'
  
               echo '&lt;h3 id="botany-words-' . $letters[$currentLetter] . '"&gt;' . $letters[$currentLetter] . '&lt;/h3&gt;';
  
  
           } 
  
          if (substr($botanyWord, 0, 1) != $letters[$currentLetter]) {  // if the first character of this botany word is different to the last              
              echo '&lt;h3 id="botany-words-' . $letters[$currentLetter] . '"&gt;' . $letters[$currentLetter] . '&lt;/h3&gt;';
  
              $currentLetter++;
          }
      ?&gt;
  
          &lt;dt&gt;&lt;?php echo $botanyWord; ?&gt;&lt;/dt&gt;
          &lt;dd&gt;&lt;?php // echo $definition; ?&gt;&lt;/dd&gt;
  
      &lt;?
      }
      echo '&lt;/dl&gt;';
  </code></pre>
  
  <p>Everytime I tried to do </p>
  
  <pre><code>if ($botanyWord == key(array_slice($content, 0, 1)) || substr($botanyWord, 0, 1) != $letters[$currentLetter]) 
  </code></pre>
  
  <p>it didn't work right, and error'd because it overflowed the 26th index (obviously being 26 chars in the alphabet).</p>
  
  <p>Thank you for your assistance!</p>