random word using a wordlist php

Solutions on MaxInterview for random word using a wordlist php by the best coders in the world

showing results for - "random word using a wordlist php"
Martina
14 Jan 2020
1// Read the whole file into a array.
2$file = file('File Location');
3
4// Getting the Words Count in the file.
5$wCount = count($file);
6
7// Printing out the random word.
8echo $file[rand(0, $wCount - 1)];
9
10// This is a one liner.
11echo file('File Location')[rand(0, count(file('File Location')) - 1)];