title: Update data on Json file using php
body: <p>i have this code to create a json file on server and save form data to that jason file.</p>
  
  <p>the problem is every time i hit submit button, form data append to existing data on json file.</p>
  
  <p>I would like to update it not create more copy line.</p>
  
  <p>here is the code, you can check it out.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <pre><code>&lt;?php
  if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  
      move_uploaded_file($_FILES["Photo"]["tmp_name"],"images/".$_POST['Photo']);
  
      $filters=array(
          "FirstName",
          "LastName",
          "Photo",
          "MobilePhone",
          "MobilePhoneProvider",
          "HomePhone",
          "HomePhoneProvider",
          "WorkPhone",
          "WorkPhoneProvider"
      );
  
      $final=array();
  
      foreach ($filters as $filter) {
          $final[$filter]=$_POST[$filter]?$_POST[$filter]:"";
      }
  
      $final["PhoneNumber"]=array(
          array(
              "MobilePhone"=&gt;$final["MobilePhone"],
              "Provider"=&gt;$final["MobilePhoneProvider"],
          ),
          array(
              "HomePhone"=&gt;$final["HomePhone"],
              "Provider"=&gt;$final["HomePhoneProvider"],
          ),
          array(
              "WorkPhone"=&gt;$final["WorkPhone"],
              "Provider"=&gt;$final["WorkPhoneProvider"],
          )
      );
  
      $unsets=array(
          "MobilePhone",
          "MobilePhoneProvider",
          "HomePhone",
          "HomePhoneProvider",
          "WorkPhone",
          "WorkPhoneProvider"
      );
  
      foreach ($unsets as $unset) {
          unset($final[$unset]);
      }
  
  
  
  $json = json_encode( $final );
  $file = 'entries.json';
  file_put_contents( $file, $json, FILE_APPEND);
  
      exit;
  }
  ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Contact&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form action="" method="post" enctype="multipart/form-data"&gt;
              First Name: &lt;input type="text" name="FirstName"&gt;&lt;br&gt;
              Last Name: &lt;input type="text" name="LastName"&gt;&lt;br&gt;
              Photo: &lt;input type="file" name="Photo"&gt;&lt;br&gt;
              Mobile Phone: &lt;input type="tel" name="MobilePhone"&gt;&lt;br&gt;
              Mobile Phone Provider: &lt;input type="text" name="MobilePhoneProvider"&gt;&lt;br&gt;
              Home Phone: &lt;input type="tel" name="HomePhone"&gt;&lt;br&gt;
              Home Phone Provider: &lt;input type="text" name="HomePhoneProvider"&gt;&lt;br&gt;
              Work Phone: &lt;input type="tel" name="WorkPhone"&gt;&lt;br&gt;
              Work Phone Provider: &lt;input type="text" name="WorkPhoneProvider"&gt;&lt;br&gt;
              &lt;input type="submit"&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>