Echo-ing array elements in PHP with foreach loop
<p>I am trying to test if multiple files exist by the URL in PHP with a foreach loop.</p>

<p>For some reason i am only appending the last URL to the array and I cannot find out why.</p>

<p>It should print out like:</p>

<pre><code>TEST.COM/sky.jpg exists.
TEST.COM/water.jpg doesnt exist
TEST.COM/trees.jpg exists.
</code></pre>

<p>But the last url only appends, which is <code>trees.jpg</code>.</p>

<p>Here is my code, I'm not too well at PHP. Maybe a little misunderstanding of the <code>foreach</code> function.</p>

<p>Where have I gone wrong?</p>

<pre><code>$neg = 'doesnt exist';
$exists = 'exists.';
$file = $_POST['URL'];
$terms = array('sky.jpg','water.jpg','trees.jpg');
reset($terms);
$list = array();
foreach ($terms as &amp;$i){
    $fullurl = $file.$i;
    $file_headers = @get_headers($fullurl);}
    if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
        array_push($list,$fullurl." ".$neg);}
    else {array_push($list,$fullurl." ".$exists);}
foreach ($list as &amp;$x){echo $x;}
?&gt;
</code></pre>
