我希望在用户刷新页面时从random.txt
中随机调用单词,但我只得到了$word_array[0]
而没有其他的$word_array[1..3]。
random.txt
hello
how
are
you
PHP 代码:
myfile = fopen("random.txt", "r") or die("Unable to open file!");
$word_array = array(fgets($myfile));
$word = rand(0,4);
$lines[] = fgets($myfile);
echo $word_array[$word];
fclose ($myfile);
这是什么错误?
更新:如果可以避免循环,并且仅更正此代码。