title: how add new data to array json with php?
body: <p>I have 4 input, which sent by Ajax 4 data, to a php file:
  how can I load json file and then add new data whih php?</p>
  
  <pre><code>&lt;input type="text" id="name"&gt;
  &lt;input type="text" id="surname"&gt;
  &lt;input type="text" id="mobile"&gt;
  &lt;input type="text" id="email"&gt;
  &lt;script&gt;
  var name = $("#name").val();
  var surname = $("#surname").val();
  var mobile = $("#mobile").val();
  var email = $("#email").val();
  $.ajax({type:"POST",
  url:"fill.php",
  data:"name="+nombre+"&amp;surname="+surname+"&amp;mobile="+mobile+"&amp;email="+email,
  success:function(data) {
  </code></pre>
  
  <p>}
  });
  JSON file: (people.json)</p>
  
  <pre><code>{
  "1":
  {
      "Name" : "Jhon",
      "Surname" : "Kenneth",
      "mobile" : 329129293,
      "email" : "jhon@gmail.com"
  },
  "2":
  {
      "Name" : "Thor",
      "Surname" : "zvalk",
      "mobile" : 349229293,
      "email" : "thor@gmail.com"
  }
  }
  </code></pre>
  
  <p>here I have a mistake fill.php file :</p>
  
  <pre><code>&lt;?php
  $name = $_POST['name'];
  $surname =$_POST['surname'];
  $mobile = $_POST['mobile'];
  $email =$_POST['email'];
  $file = 'people.json';
  $data = json_decode(file_get_contents($file));
  $newdata = array('name'=&gt;$name, 'surname' =&gt; $surname, 'mobile'=&gt;$mobile,'email'=&gt;$email);
  $data[] = $newdata;
  file_put_contents($file, json_encode($data));
  ?&gt;
  </code></pre>
  
  <p>when I exeute it, it delete all the people.json date, and everytime that I add new data, it give me the next result: [{},{},{},{}]</p>