title: array not working with ajax post
body: <p>everything work good except my array. when i click few time on sent the <code>count($a)</code> stay at 1.
  <code>$catbotreply</code> is the reply of my msg.</p>
  
  <pre><code>$a=array();
  array_unshift($a,$catbotreply); 
  
   &lt;script&gt;
      $(document).ready(function () {
          $("#submit").on("click", function (event) {
              event.preventDefault();
              $.ajax({
                  type: "POST",
                  url: "index.php",
                  data: $("#catbot").serialize() + "&amp;d=d",
                  success: function (data) {
                      console.log(data);
                      $('#catbotResult').html(data);
                  }
              });
          });
      });
  &lt;/script&gt;
  
  
  
   if (isset($_POST['msg'])) {
  
  
  
  
  
     $response.= ' &lt;b class="yousay"&gt;You say:&lt;/b&gt;' . stripslashes($usermessage) . '&lt;br /&gt;&lt;br /&gt;';
  $response.= '&lt;b class="catbotsays"&gt;Bot:&lt;/b&gt;' . $catbotreply . '&lt;br /&gt;&lt;br /&gt;';
   $response.= count($a);              
  echo $response;
  }
  
  
  
  
  
  
       &lt;form name="catbot" id="catbot" action="&lt;?php echo($_SERVER["PHP_SELF"]); ?&gt;" method="POST"&gt;
                      &lt;b&gt;Msg:&lt;/b&gt;
                      &lt;input type="text" name="msg" size="30" class="text"&gt;
                      &lt;input type="submit" id="submit" name="submit" value="Send!" class="bttn"&gt;
                      &lt;input type="text" name="lastcatbot" value="&lt;?php echo $simplecatbot; ?&gt;"&gt;
                      &lt;input type="text" name="lastwascomm" value="&lt;?php echo $command; ?&gt;"&gt;
                  &lt;/form&gt;
  
                  &lt;hr&gt;
                  &lt;div class="leftalign" id="catbotResult"&gt;
                      &lt;b class="yousay"&gt;You say:&lt;/b&gt;Connected!&lt;br /&gt;&lt;br /&gt;
                      &lt;b class="catbotsays"&gt;Bot:&lt;/b&gt;Connected!&lt;br /&gt;&lt;br /&gt;
                  &lt;/div&gt;
  </code></pre>
  
  <p>before i add the ajax function i was using a hidden text to save my last msg and i understand if i use echo in the same page the data won't refresh so its why i added the <code>count($a)</code> to <code>$response</code>. my msg and bot reply refresh at every msg but my count stay at 1 . anyone know why?</p>