You’re using the wrong resource.
There is the shuffle
for this, see in the http://php.net/manual/en/function.shuffle.php.
The shuffle
does just make the array in random order, so the defined order is ignored, including the indices!
The simplest way to solve what you want is exactly:
PHP:
<?php
$times = array('', 'Corinthians', 'Santos', 'Flamengo');
shuffle($times);
foreach($times as $time){
?>
<div>
<input type="radio" name="quiz1" value="A">
<label for="questao1-A"><?= $time ?></label>
</div>
<?php } ?>
Test me here!
Upshot:
<div>
<input type="radio" name="quiz1" value="A">
<label for="questao1-A"></label>
</div>
<div>
<input type="radio" name="quiz1" value="A">
<label for="questao1-A">Flamengo</label>
</div>
<div>
<input type="radio" name="quiz1" value="A">
<label for="questao1-A">Corinthians</label>
</div>
<div>
<input type="radio" name="quiz1" value="A">
<label for="questao1-A">Santos</label>
</div>
Note:
Shift to the foreach
is optional, but for me improves the reading of
code and reduces the numerous uses of []
next to the parameter, which can
confuse.
Because dude, vlwzão, I had found a tutorial on the net, that had to do function and tals, a code of more or less 15 lines, this one saved
– Renan