Fwrite in foreachloop PHP
<p>I want to write the contents of an array to new file.</p>

<p>So far as it stands my file is only containing the last element of my array and not the first two.  So the text in the file output2.txt is Edward only.</p>

<p>Have I misunderstood something here?</p>

<pre><code>$array = array ("Sarah", "William", "Edward");

foreach ($array as $value) {
    $myfile = fopen("output2.txt", "w") or die("Unable to open file!");
    fwrite($myfile,$value);
    fclose($myfile);
} 
</code></pre>