如何使用PHP从文本文件(数组)中选择一个随机单词


How to pick a random word from text file (array) using PHP?

如何从逗号分隔的单词文件中随机选择一个单词?

$var = file_get_contents('the_file.txt'); //Take the contents from the file to the variable
$result = explode(',',$var); //Split it by ','
echo = $result[array_rand($result)]; //Return a random entry from the array.
echo explode(',',file_get_contents('file.txt'))[rand(0,99)];

用最少的代码。