php array populated with command does not evaluate same as hard coding array with same value
<p>This is the third posting of this type, now I can speak to what is happening.
Here is the code anyone can try it.
When populating the array hostname with the name localhost using the grep command and then evaluating using <code>file_exists</code> it does not work.  </p>

<p>If you assign localhost to the array and then evaluate using <code>file_exists</code> it works.  I had 2 previous posts and thought the issue was with the "<code>file_exists</code>" but as it turns out it is not.
Please try the code below twice using the code below.  </p>

<p>It will create the /tmp/localhost file.  Then run it again and it will not find the file.
Try it again with the localhost assigned to the array and it works.</p>

<p>Why is the value for some reason different even though it is the same?</p>

<pre><code>#!/usr/bin/php -q
&lt;?php

$i = 1;
$hostname = array();
$hostname[$i] = `grep 127.0.0.1 /etc/hosts |awk '{print $3}'`;

// hostname[$i]="localhost";
echo "hostname[$i] = $hostname[$i]\n";
if (file_exists("/tmp/$hostname[$i]")) {
    echo "do nothing file exists\n";
} else {
    echo "No file exists create one\n";
    $touch = `touch /tmp/$hostname[$i]`;
}
</code></pre>
