title: How to update an item in a Json object in PHP
body: <p>I have a json object like this : </p>
  
  <pre><code>  {
          "fields" : 
          [
              {
                "name" : "news_title",
                "type" : "text",
                "value" : "old title"
              },
              {
                "name" : "news_content",
                "type" : "textarea",
                "value" : "old content"
              }
          ]            
    }
  </code></pre>
  
  <p>and I have a form that bring me only the values for these fields :</p>
  
  <pre><code>Array
  (
      [news_title] =&gt; My new title
      [news_content] =&gt; My new content
      [other_values_doesnt_mach_json_file] =&gt; always comes at the end of the array
  )
  </code></pre>
  
  <p>My goal is to update that json object with the new values .. so I get the json object with the new values like so :</p>
  
  <pre><code>  {
          "fields" : 
          [
              {
                "name" : "news_title",
                "type" : "text",
                "value" : "My new title"
              },
              {
                "name" : "news_content",
                "type" : "textarea",
                "value" : "My new content"
              }
          ]            
    }
  </code></pre>
  
  <p>Here I can loop through the Json object ..</p>
  
  <pre><code>$source = json_decode($oldjson);
  
  foreach($source-&gt;fields as $field){
          echo $field-&gt;name .' - '. $field-&gt;value .' &lt;br /&gt;';
          //$field-&gt;value =  'test'; Here I'm trying to update the values of each field with the new data ..
  }
  </code></pre>
  
  <p>And here how I can loop through my new values array ..</p>
  
  <pre><code>    // laravel post 
  foreach(Input::get() as $name =&gt; $value){
      echo $name .' : '. $value .' &lt;br /&gt; ' ;
  }
  </code></pre>
  
  <p>But I have no idea how to combine those tow to get a new json object with the new values. </p>
  
  <p>Thanks in advance for your help </p>