title: Merging multiple JSON files with array_merge_recursive
body: <p>I have multiple JSON files (over 120) which I want to merge into one single file using <code>array_merge_recursive</code> but I'm getting an <code>Argument #1 is not an array</code> error.</p>
  
  <p>Taking two individual files gives me the desired solution, but <strong>trying to loop through all the files</strong> gives me the error.</p>
  
  <p>Any help on this greatly appreciated – I've tried many, many different tweaks on the code below and nothing is giving me any joy.</p>
  
  <pre><code>//The folder where the files are kept
  $filenames = glob('Week6/*.json');
  
  //Loading one file to start the merge (it has some content),
  //convert from JSON format to a usable array
  $arrayThree = file_get_contents('newMerge.json');
  $arrayThree = json_decode($arrayThree);
  
  //Loop through all of the filenames…
  foreach ($filenames as $filename) {
  
  //Get a JSON file from the list
  $arrayTwo = file_get_contents($filename);
  $arrayTwo = json_decode($arrayTwo);
  
  //Here's where I'm trying to merge the original and the new
  //overwriting the initial variable created outside the loop, to be used again
  $arrayThree = array_merge_recursive($arrayThree, $arrayTwo);
  
  }
  
  //Encode again as JSON, save out and empty
  $arrayThree = json_encode($arrayThree);
  file_put_contents("newMerge2.json", $arrayThree);
  unset($arrayThree);//release memory
  </code></pre>