What are the potential pitfalls of using a loop to generate random questions in PHP?
One potential pitfall of using a loop to generate random questions in PHP is that the same question may be repeated multiple times. To solve this issue, you can shuffle the array of questions before looping through them to ensure a random order each time.
// Array of questions
$questions = [
"Question 1",
"Question 2",
"Question 3",
// Add more questions as needed
];
// Shuffle the array of questions
shuffle($questions);
// Loop through the shuffled questions
foreach ($questions as $question) {
echo $question . "<br>";
}