在上一个问题中,我没有意识到我自己无法添加其余的更改,所以这就是我正在使用的。用户 webfix 帮助我得到了这个:
$mars = array ('How big is Mars?', 'How many moons does Mars have?', 'How far away is Mars?', 'What is the highest point on Mars?');
$jupiter = array ('How big is Jupiter?', 'How many moons does Jupiter have?', 'How far away is Jupiter?', 'What is the highest point on Jupiter?');
$earth = array ('How big is Earth?', 'How many moons does Earth have?', 'How far away is Earth?', 'What is the highest point on Earth?');
$sun = array ('How big is the Sun?', 'How many moons does the Sun have?', 'How far away is the Sun?', 'What is the highest point on the Sun?');
$all = array($mars, $jupiter, $earth, $sun);
function createList($a)
{
echo "<ul>";
foreach ($a as $array)
{
$questions = count($array);
$idquestion = rand(0, $questions-1);
echo "<li>" . $array[$idquestion] . "</li>";
}
echo "</ul>";
}
createList($all);
我现在想添加问题顺序的随机化以及最多三个(或稍后更改的任何数量)问题吐出。
它目前将选择每个问题中的一个($mars、$jupiter、$earth、$sun),然后按该顺序将其放入列表中。我希望顺序是随机的,并且只选择其中三个。
我尝试使用“shuffle ($all)”,但这不起作用,也许我们可以使用类似“for ($i = 1; $i < 4; $i++)”的东西让它在选择三个后停止? 谢谢。