title: Searching for Array Key in $_POST, PHP
body: <p>I am trying to add commenting like StackOverflow and Facebook uses to a site I'm building. Basically, each parent post will have its own child comments. I plan to implement the front-end with jQuery Ajax but I'm struggling with how to best tackle the PHP back-end.</p>
  
  <p>Since having the same name and ID for each form field would cause validation errors (and then some, probably), I added the parent post's ID to each form field. Fields that will be passed are commentID, commentBody, commentAuthor - with the ID added they will be <code>commentTitle-12</code>, etc.</p>
  
  <p>Since the <code>$_POST</code> array_key will be different each time a new post is processed, I need to trim off the <code>-12</code> (or whatever the ID may be) from the <code>$_POST</code> key, leaving just commentTitle, commentBody, etc. and its associated value.</p>
  
  <p>Example</p>
  
  <pre><code>$_POST['commentTitle-12']; //how it would be received after submission
  $_POST['commentTitle']; //this is what I am aiming for
  </code></pre>
  
  <p>Many thanks</p>
  
  <p><strong>SOLUTION</strong>
  Thanks to CFreak-</p>
  
  <pre><code>//Basic example, not actual script
  &lt;?php
  if (array_key_exists("send", $_POST)) {
      $title = $_POST['title'][0];
      $body = $_POST['body'][0];
      echo $title . ', ' . $body;
  }
  ?&gt;
  &lt;html&gt;
  &lt;body&gt;
  &lt;form name="test" id="test" method="post" action=""&gt;
  &lt;input type="text" name="title[]"/&gt;
  &lt;input type="text" name="body[]"/&gt;
  &lt;input type="submit" name="send" id="send"/&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Update 2</strong>
  Oops, kind of forgot the whole point of it - unique names (although it's been established that 1) this isn't really necessary and 2) probably better, for this application, to do this using jQuery instead)</p>
  
  <pre><code>//Basic example, not actual script
      &lt;?php
      if (array_key_exists("send", $_POST)) {
          $id = $_POST['id'];
          $title = $_POST['title'][$id];
          $body = $_POST['body'][$id];
          echo $title . ', ' . $body;
      }
      ?&gt;
      &lt;html&gt;
      &lt;body&gt;
      &lt;form name="test" id="test" method="post" action=""&gt;
      &lt;input type="text" name="title[&lt;?php echo $row['id'];?&gt;]"/&gt;
      &lt;input type="text" name="body[&lt;?php echo $row['id'];?&gt;]"/&gt;
      &lt;input type="hidden" name="id" value="&lt;?php echo $row['id']; //the ID?&gt;"/&gt;
      &lt;input type="submit" name="send" id="send"/&gt;
      &lt;/form&gt;
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>