UPDATE! ADDING PHP code
<?php
$tq_array = array();
$c_array = array();
$o1_array = array();
$o2_array = array();
$o3_array = array();
$questions = mysql_query("SELECT * FROM test WHERE exam_code = '$exam'");
while($row = mysql_fetch_assoc($questions)){
$tq_array[] = $row['test_question'];
$c_array[]= $row['correct_answer'];
$o1_array[] = $row['option_1'];
$o2_array[] = $row['option_2'];
$o3_array[] = $row['option_3'];
}
$tq_json = json_encode($tq_array);
$c_json = json_encode($c_array);
$o1_json = json_encode($o1_array);
$o2_json = json_encode($o2_array);
$o3_json = json_encode($o3_array);
?>
我的问题是我想将这个转换后的javascript数组(从php数组)添加到另一个存储。在单个javascript数组中添加很多javascript数组
var questioner = JSON.parse('<?= $tq_json; ?>');
var correct_ans = JSON.parse('<?= $c_json; ?>');
var option1 = JSON.parse('<?= $o1_json; ?>');
var option2 = JSON.parse('<?= $o2_json; ?>');
var option3 = JSON.parse('<?= $o3_json; ?>');
这就是我要添加代码
var i = 0
for(i = 0; i <= obj1.length;i++){
var questions = [
[ /* this is the one that fix the counting of the questioners*/],
[[obj1[i], obj2[i], obj3[i], obj4[i], obj5[i]],"false",1],
],
sec=20,
A;
}
我尝试循环使用循环,但它没有工作的存储。
我喜欢出现像这样()
var questions = [
[ /* this is the one that fix the questioner */],
[[obj1[i], obj1[i], obj1[i], obj1[i], obj1[i]],"false",1],
[[obj2[i], obj2[i], obj2[i], obj2[i], obj2[i]],"false",1],
[[obj3[i], obj3[i], obj4[i], obj3[i], obj3[i]],"false",1],
So on ....
],
sec=20,
A;
谢谢!
在你的代码示例你的变量不匹配了,我们不知道的PHP阵列的内容。这使得很难确切地看到你的意思。你能否更新这个。 – Mouser