【发布时间】:2017-01-03 16:33:05
【问题描述】:
我正在尝试使用相同的随机变量返回 2 个不同的数组。所以我有:
function TransTest() {
$TransQ = array();
$TransA = array();
$TransQ[0] = "Q1";
$TransQ[1] = "Q2";
$TransQ[2] = "Q3";
$TransQ[3] = "Q4";
$TransA[0] = "Ans 1";
$TransA[1] = "Ans 2";
$TransA[2] = "Ans 3";
$TransA[3] = "Ans 4";
$index = rand(0, count($TransQ)-1);
return $TransQ[$index];
}
所以这基本上从$TransQ 数组中返回一个随机问题。我想做的是返回问题的相应答案。
类似于:
return ($TransQ[$index] && $TransA[$index]);
但这似乎不起作用。请帮忙。
【问题讨论】:
-
return ['Question' => $TransQ[$index], 'Answer' => $TransA[$index]];