Global variables in PHP
<p>I'm writing a script that will select a random word from among words in an input file, multiple times. Now calling <code>file()</code> multiple times seems inefficient, so I'm thinking of having a global array for the words from the file and a function that will load the file into the array (called before selecting random words). Why doesn't it work?</p>

<pre><code>global $words;

function init_words($file)
{
    $words = file($file);
    $count = count($words);
    echo "$count words&lt;br&gt;\n"; // "3 words"
}

init_words("/foo/bar");
$count = count($words);
echo "$count words&lt;br&gt;\n"; // "0 words" 
</code></pre>
