title: Get the count of unique words from all .txt files in a directory
body: <p>I have a directory of text files. I want to loop through each of the text files in the directory and get the overall count of unique words (count of vocabulary), not for each individual file, but for ALL the files together. In other words, I want the number of unique words within all the files together, and NOT the number of unique words for each individual file.</p>
  <p>For example, I have three text files in a directory. Here are their contents:</p>
  <p>file1.txt -&gt; <code>here is some text.</code></p>
  <p>file2.txt -&gt; <code>here is more text.</code></p>
  <p>file3.txt -&gt; <code>even more text.</code></p>
  <p>So the count of unique words for this directory of text files in this case is 6.</p>
  <p>I have tried to use this code:</p>
  <pre><code>$files = glob(&quot;C:\\wamp\\dir&quot;);
  
  $out = fopen(&quot;mergedFiles.txt&quot;, &quot;w&quot;);
  
  
    foreach($files as $file){
        $in = fopen($file, &quot;r&quot;);
        while ($line = fread($in)){
             fwrite($out, $line);
        }
        fclose($in);
    }
  
  
    fclose($out);
  </code></pre>
  <p>to merge all the text files and then after using this code I planned to use the array_unique() on mergedFiles.txt. However, the code is not working.</p>
  <p>How can I get the unique word count of all the text files in the directory in the best way possible?</p>