如何在PHP中迭代而不重复

时间:2016-11-11 10:34:29

标签: php

我想在没有重复的情况下打印custom_question,并且在php中使用loop来定制custom_question_answer db的链接如下所示

enter image description here

1 个答案:

答案 0 :(得分:0)

对您有帮助并获得更清晰的想法。

<?php
$arr = $arr_history = array("1stQuestion?","2ndQuestion?","3rdQuestion?","4thQuestion?");

for ( $i = 0; $i < count($arr); $i++ )
{
    if (empty($arr_history)){ $arr_history = $arr; }
    $key = array_rand($arr_history, 1);
    $selected = $arr_history[$key];
    unset($arr_history[$key]);
    echo $selected . PHP_EOL;
}

?>