title: Php get last array key
body: <p>I'm using this code to generate JSON string, but a faced with one problem, I try to find out is this the last element or not, I am using this <code>if(end($aData) != $aD)</code> but this is comparing the value, there is a problem,  when in the array are same values, How could I compare the $keys(get the last key and compare with the current key), or get the last element.</p>
  
  <pre><code>$ret    =   '[';
          foreach($aDatas as $aData)
          {
              $ret    .=  "{";
              foreach($aData as $key=&gt;$aD)
              {               
                  $ret    .=  '"'.$key.'":"'.$aD.'"';
                  if(end($aData) != $aD)
                      $ret    .=  ',';
              }
              $ret    .=  "}";
              if(end($aDatas) != $aData)
                  $ret    .=  ',';
          }
          echo $ret.']';
  </code></pre>