title: Merging two JSON objects with PHP?
body: <p>I have two JSON objects, and I want it to be merged into one JSON object. I don't want the JSON data to be <strong>overwritten</strong>. I want the data to be <strong>merged</strong>.</p>
  
  <p><strong>Object #1: (example1.json)</strong> </p>
  
  <pre><code>[{
      "title": "xx",        
      "releaseYear": "2014",        
  },
  {
      "title": "yy",       
      "releaseYear": "2015"        
  }]
  </code></pre>
  
  <p><strong>Object #2: (example2.json)</strong></p>
  
  <pre><code>[{
      "title": "yy",       
      "releaseYear": "2017"
  
  }]
  </code></pre>
  
  <p>This is the <strong>PHP File</strong> I currently am using:</p>
  
  <pre><code>    &lt;?php
  
      $jsonString = file_get_contents('example.json');
      $jsonString2 = file_get_contents('example2.json');   
      $data = json_decode($jsonString, true);
      $data2 = json_decode($jsonString2, true);      
  
  
      $op = array_merge_recursive( $data, $data2 );
  
      $resJson = json_encode($op);
      file_put_contents('example3.json', $resJson);   
  </code></pre>
  
  <p><strong>Output received: (example3.json)</strong> </p>
  
  <pre><code>[  
     {  
        "title":"xx",
        "releaseYear":"2014"
     },
     {  
        "title":"yy",
        "releaseYear":"2015"
     },
     {  
        "title":"yy",
        "releaseYear":"2017"
     }
  ]    
  </code></pre>
  
  <p><strong>Required Output:</strong></p>
  
  <pre><code>[{
      "title": "xx",        
      "releaseYear": "2014"        
  },
  {
      "title": "yy",       
      "releaseYear": "2017"        
  }]
  </code></pre>
  
  <p>Solutions appreciated. Am new to Stackoverflow, so sorry for my bad formatting, if any. Thanks in advance :)</p>