I'm writing a script that will select a random word from among words in an input file, multiple times. Now calling file()
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?
global $words;
function init_words($file)
{
$words = file($file);
$count = count($words);
echo "$count words<br>\n"; // "3 words"
}
init_words("/foo/bar");
$count = count($words);
echo "$count words<br>\n"; // "0 words"