当我print_r($ choices)时,它表明该数组已改组,但是当我不打印时,什么也没发生。是否可以通过单选按钮应用/合并随机选择。
查看:
<?php if(count($questions) > 0):?>
<?php $index = 1; ?>
<?php foreach($questions as $row):?>
<p><?=$index++?>. <b><?=$row->ques?></b></p>
<?php $choices= array($row->ch_des1, $row->ch_des2, $row->ch_des3, $row->ch_des4);
shuffle($choices);
print_r($choices);
?>
<input type="radio" name="ch_id<?=$row->ch_id?>" value="<?=$row->ch_des1?>"> <?=$row->ch_des1?><br>
<input type="radio" name="ch_id<?=$row->ch_id?>" value="<?=$row->ch_des2?>"> <?=$row->ch_des2?><br>
<input type="radio" name="ch_id<?=$row->ch_id?>" value="<?=$row->ch_des3?>"> <?=$row->ch_des3?><br>
<input type="radio" name="ch_id<?=$row->ch_id?>" value="<?=$row->ch_des4?>"> <?=$row->ch_des4?><br>
<?php endforeach;?>
<?php else:?>
<tr>
<td>No records found!</td>
</tr>
<?php endif;?>
答案 0 :(得分:1)
您可以这样做:
<?php if(count($questions) > 0):?>
<?php $index = 1; ?>
<?php foreach($questions as $row):?>
<p><?=$index++?>. <b><?=$row->ques?></b></p>
<?php
$choices= array($row->ch_des1, $row->ch_des2, $row->ch_des3, $row->ch_des4);
shuffle($choices);
?>
<?php foreach($choices as $ch_des):?>
<input type="radio" name="ch_id<?=$row->ch_id?>" value="<?=$ch_des?>"> <?=$ch_des?><br>
<?php endforeach;?>
<?php endforeach;?>
<?php else:?>
<tr>
<td>No records found!</td>
</tr>