You're using the wrong feature.
shuffle
exists for this, see the manual at link .
The shuffle
just causes the array to be randomized, 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!
Result:
<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:
Changing to foreach
is optional, but for me it improves reading
code and reduces the countless uses of []
next to the parameter, which can
confuse.