I want to call random words from the random.txt
as the user refreshes the page but I get $word_array[0]
only and not any other $word_array[1..3].
random.txt
hello
how
are
you
PHP code:
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);
What is the error?
update: If loops can be avoided, and correct this code only.