title: Trim unwanted characters from the end of the last element in an array
body: <p>How do I modify the last element in an array?</p>
  <p>The array looks like this:</p>
  <pre><code>$fields = array(&quot;firstName = 'Bob', &quot;,
                  &quot;lastName = 'Smith', &quot;,
                  &quot;email = 'bob@example.com', &quot;,
                  &quot;address = '123 anystreet', &quot;);
  </code></pre>
  <p>The array is generated by a script which creates the values and adds the comma/space at the end of each string. I want to remove that comma/space from only the last element in that array. Keep in mind that the values could in fact contain a comma/space combination so only the last element and the last two characters of the last element need to be removed.</p>
  <p>I've looked at the <code>end()</code> function but I don't think that is going to help since it just gets the value.</p>
  <p><strong>Edit</strong> Ok so I created this function/array so that I would only have one mysql function to update users. Sort of like a detect changes function and it only passes back the required/changed fields. I didn't realize there were problems associated with this approach. I thought that since I already had the mysql queries written in my old functions there shouldn't be an issue with this way. The file that it's in will not be accessible to the public. I'm going to use the best answer that works for me but I'm going to search for why this is problematic and I would appreciate comments/links as to what is wrong with this approach.</p>