0
Good, I have the following list of responses taken from my database. And in order for the right question not to be in the same place, I made an Random to show the results randomly. But the problem is that when listing, the results also repeat themselves, and I didn’t want such a thing to happen.
I would appreciate any help so that when doing the Random, the results would not be repeated.
And how can I do an answer post, since I have them dynamically?
$radioname = "pergunta-" . $row['idPergunta'];
$items =[
$row['RespostaCorrecta'],
$row['RespostaErrada1'],
$row['RespostaErrada2'],
$row['RespostaErrada3'],
];
$rand_items = [
$items[rand(0, count($items) - 1)],
$items[rand(0, count($items) - 1)],
$items[rand(0, count($items) - 1)],
$items[rand(0, count($items) - 1)],
];
echo <<<HTML
<fieldset name='pergunta-$radioname' id='pergunta-$radioname' >
<input type='radio' required name='pergunta-$radioname' id='pergunta-$radioname' > {$rand_items[0]}
<input type='radio' required name='pergunta-$radioname' id='pergunta-$radioname' > {$rand_items[0]}
<input type='radio' required name='pergunta-$radioname' id='pergunta-$radioname' > {$rand_items[0]}
<input type='radio' required name='pergunta-$radioname' id='pergunta-$radioname' > {$rand_items[0]}
</fieldset>
HTML;
I’ve thought about using shuffle, but I don’t know how to apply my code
– Paulo