title: PHP: how to update json fields
body: <p>I am passing three arguments to update a record stored in json file.
  The records are dynamically created and saved according to the user's wish.
  The following code successfully finds the id in the json file but fails in updating the record.
  Please help me to complete the update task!!</p>
  
  <pre><code>//&lt;$_GET sid desired ID, gid name of the json file to search in, and $nam array of new values&gt;
  
  $jsonitem = file_get_contents("folder1/".$gid.".txt");
  $objitems= jsonp_decode($jsonitem,true);
  foreach ($objitems as $row) {
      if ($row['id']==$sid) {
          $i=0;
          foreach ($row as $field =&gt; $value){
              $field-&gt;value = $nam[$i]; //this statement does not save the new values in the array!!
              $i++;
          }   
      }
  }
  $jsondata = json_encode($objitems,JSON_PRETTY_PRINT);
  $jsondata = "jsonp(" . $jsondata . ")";
  file_put_contents("folder1/".$gid.".txt", $jsondata);
  </code></pre>