title: PHP Foreach If Array Last
body: <pre><code>foreach( $tabs2 as $tab2 =&gt; $name ){
      $class = ( $tab2 == $current ) ? ' current' : '';
      echo("&lt;li class='posts'&gt;&lt;a href='?page=pigg&amp;tab=help&amp;tab2=$tab2' class='$class'&gt;$name");
      echo(' |'); // If array last then do not display
      echo('&lt;/a&gt;&lt;/li&gt;');
  }
  </code></pre>
  
  <p>I'm using a foreach loop to create a navigation for a WordPress plugin I'm working on, but I don't want the ' |' to be displayed for the last element, the code above is what I've got so far, I was thinking of using an if statement on the commented line, but not sure what the best approach would be, any ideas? Thanks!</p>