title: merge all files in directory to one text file
body: <p>In PHP, how can I open everyfile, all text files, in a directory and merge them all into one text file.</p>
  
  <p>I don't know how to open all files in a directory, but I would use the <code>file()</code> command to open the next file and then a foreach to append each line to an array.
  like so:</p>
  
  <pre><code>$contents = array();
  $line = file(/*next file in dir*/);
  foreach($lines as line){
     array_push($line, $contents);
  }
  </code></pre>
  
  <p>Then I would write that array to a new text file one I've reached no more files in the directory.</p>
  
  <p>if you have a better way of doing this then please let me know.</p>
  
  <p>Or if you can help me implement my solution especially the opening the next file in the dir, please let me know!</p>