1. Define an array.
$my_array = array();
2. Create a key for each string. You don't have to specify an index number (the number inside the brackets [ ] ) for each key, but I am doing so to make the flow better understandable.
$my_array[0] = "A";
$my_array[1] = "B";
$my_array[2] = "C";
$my_array[3] = "D";
$my_array[4] = "E";
$my_array[5] = "F";
$my_array[6] = "G";
$my_array[7] = "H";
$my_array[8] = "I";
$my_array[9] = "J";
$my_array[10] = "K";
$my_array[11] = "L";
$my_array[12] = "M";
$my_array[13] = "N";
$my_array[14] = "O";
$my_array[15] = "P";
$my_array[16] = "Q";
$my_array[17] = "R";
$my_array[18] = "S";
$my_array[19] = "T";
$my_array[20] = "U";
$my_array[21] = "V";
$my_array[22] = "W";
$my_array[23] = "X";
$my_array[24] = "Y";
$my_array[25] = "Z";
3. We need to store the highest index number (in this case '25') in a variable. This array has 26 items, but the highest index number is '25' because arrays start at '0'. So we count the size of the array using count($my_array), and then subtract '1' from it.
$array_size = count($my_array) - 1;
4. Now generate a random number between '0' (the lowest number in the array) and the value you've stored in the variable above. This will generate a random index number that matches an index number inside your array.
$random_index = mt_rand(0,$array_size);
5. Print the random key by putting the generated number above inside the brackets.
echo $my_array[$random_index];
The complete code:
// An array with some text.
// Modify it to contain the random texts it will show.
$my_array = array();
$my_array[0] = "A";
$my_array[1] = "B";
$my_array[2] = "C";
$my_array[3] = "D";
$my_array[4] = "E";
$my_array[5] = "F";
$my_array[6] = "G";
$my_array[7] = "H";
$my_array[8] = "I";
$my_array[9] = "J";
$my_array[10] = "K";
$my_array[11] = "L";
$my_array[12] = "M";
$my_array[13] = "N";
$my_array[14] = "O";
$my_array[15] = "P";
$my_array[16] = "Q";
$my_array[17] = "R";
$my_array[18] = "S";
$my_array[19] = "T";
$my_array[20] = "U";
$my_array[21] = "V";
$my_array[22] = "W";
$my_array[23] = "X";
$my_array[24] = "Y";
$my_array[25] = "Z";
// Get the size of the array for getting the highest index number.
// Arrays start at '0', so we subtract 1 from the total amount.
// Key number '26' will have an index of '25'
$array_size = count($my_array) - 1;
// Generate a number between 0 and the highest index number of the array
$random_index = mt_rand(0,$array_size);
// Print the array key with the generated index number
echo $my_array[$random_index];