title: Find the last element of an array while using a foreach loop in PHP
body: <p>I am writing a SQL query creator using some parameters. In Java, it's very easy to detect the last element of an array from inside the for loop by just checking the current array position with the array length.</p>
  
  <pre><code>for(int i=0; i&lt; arr.length;i++){
       boolean isLastElem = i== (arr.length -1) ? true : false;        
  }
  </code></pre>
  
  <p>In PHP they have non-integer indexes to access arrays. So you must iterate over an array using a foreach loop. This becomes problematic when you need to take some decision (in my case to append or/and parameter while building query). </p>
  
  <p>I am sure there must be some standard way of doing this. </p>
  
  <p>How do you solve this in PHP?</p>