title: PHP if there is DATA replace else write data
body: <p>I may be missing something in my PHP code. I'd like if the data.json file doesn't contain any array with the posted ID then create if is it's there then change the point to +1. Sorry if my not very clear my english is not the best.
  Here is my code thanks for helping.</p>
  
  <pre><code>    &lt;?php
  
  header('Access-Control-Allow-Origin: *');
  header('Access-Control-Allow-Methods: GET, POST');
  header("Access-Control-Allow-Headers: X-Requested-With");
  
  $date               = date("c");
  $id                 = $_POST['id'];
  $file               = 'data.json';
  
  $nom                = $_POST['nom'];
  $description        = $_POST['description'];
  $adresse            = $_POST['adresse'];
  $telephone          = $_POST['telephone'];
  $img                = $_POST['img'];
  $points             = $_POST['points'];
  
  $data1 = array(
   "date"          =&gt; $date,
   "ID"            =&gt; $id,
   "nom"           =&gt; $nom,
   "description"   =&gt; $description,
   "adresse"       =&gt; $adresse,
   "telephone"     =&gt; $telephone,
   "img"           =&gt; img,
   "points"        =&gt; "1",
  );
  
  $replace=array( /* Replace these keys with these values */
      'date'          =&gt;  $date,
      'points'        =&gt;  ++$points,
  );
  
  
  $keys=array_keys( $replace );
  
  $strjson= file_get_contents($file);
  
  $json=json_decode( $strjson );
  
  
  for ($i = 0; $i &lt; count($json); $i++) {
  
    // if we found it,
    if ($json[$i]-&gt;id != $id) {
        array_push($json, $data1);
  $jsonData = json_encode($json);
  file_put_contents($file, $jsonData);
  
          } else {
  foreach( $replace as $key =&gt; $value ){
              $obj-&gt;$key=$value;
          }
  $json = array_values($json);
  $fp = fopen($file, 'w');
  fwrite($fp, json_encode($json));
  fclose($fp);
  
    }
  }
  
  ?&gt;  
  </code></pre>