I made a quiz that generates a random answer at the end by using the shuffle()
function.
I want it to stay on the same answer and not to shuffle again.
My code:
<?php
//Array of cars
$answer = array(
"Mercedes",
"Benz",
"Honda",
"Toyota",
"Nissan",
"Mazda",
"Hyundai",
"Ford",
"Lexus",
"Lamborghini",
"Ferrari",
"Porche",
"Mitsubushi",
"Scion",
"Chrysler",
"Jeep",
"Masarati"
);
// Shuffle the order
shuffle($answer);
echo $answer[0];
?>
For example: if $answer
was shuffled and generated "Mitsubushi" ---
when I refresh the page it should stay "Mitsubushi" but what happens
is that when the page is refreshed it reshuffles again.
So when I refresh the page, it echo
's another thing do the shuffle()
function.
Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…