要显示混洗的选择?

时间:2019-07-03 05:18:18

标签: php codeigniter

当我print_r($ choices)时,它表明该数组已改组,但是当我不打印时,什么也没发生。是否可以通过单选按钮应用/合并随机选择。

这是输出: Output

查看:

 <?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;?>

1 个答案:

答案 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>