title: Write array elements on new line in text file
body: <p>I am trying to alphabetize then remove duplicates out of this array. Then I am trying to write each element in the array to its own line in a text file.</p>
  
  <p>Meaning only one element of the sorted and unique array will be on a line.</p>
  
  <p>But all I am getting is a blank text file.</p>
  
  <p>How can I write the contents of this array, <code>$sorted_lines</code> to a text file so that each element is on a new line?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;?php
  $lines = file('american.txt');
  $lines = array_walk($lines, 'trim'); 
  $sorted_lines = sort(array_unique($lines));
  $out = fopen("new.txt", "w");
  foreach($sorted_lines as $line){
      $line .= "\n";
      fwrite($out, $line);
  }
  ?&gt;
  </code></pre>