Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何动态传递数组索引值_Php_Jquery_Ajax_Arrays_Codeigniter - Fatal编程技术网

Php 如何动态传递数组索引值

Php 如何动态传递数组索引值,php,jquery,ajax,arrays,codeigniter,Php,Jquery,Ajax,Arrays,Codeigniter,我想知道如何动态获取数组索引值 在这里,我正在定制编码中使用的quizy-fillinetblanks.master.zip文件: <script> $('#tutorial-fillblank').quizyFillBlank({ textItems:['The first president of the United States of America is', '. The longest serving president of the country is '

我想知道如何动态获取数组索引值

在这里,我正在定制编码中使用的quizy-fillinetblanks.master.zip文件:

<script>
  $('#tutorial-fillblank').quizyFillBlank({
    textItems:['The first president of the United States of America is', '. The longest serving president of the country is ', '. He was succeeded by ', ', who led the country till the end of the Second World War. The first afro-american to be elected for this position is', '.'],
    anItems:['John Kennedy', 'Franklin Roosevelt', 'George Washington', 'Ronald Reagan', 'Harry Truman', 'Richard Nixon', 'Barack Obama' ], 
    anItemsCorrect:[2,1,4,6],
    blockSize:150
  });
</script>

$(“#教程填充空白”).quizyFillBlank({
文本项目:[“美利坚合众国第一任总统是”,该国任期最长的总统是,他由,继任,领导该国直到第二次世界大战结束。第一位当选担任这一职务的非裔美国人是,],
anItems:[“约翰·肯尼迪”、“富兰克林·罗斯福”、“乔治·华盛顿”、“罗纳德·里根”、“哈里·杜鲁门”、“理查德·尼克松”、“巴拉克·奥巴马”],
anItemsCorrect:[2,1,4,6],
区块大小:150
});
在上面的编码文本中,items是问题,anitem是答案,anItemCorrect是anitem的数组索引值

在这种编码中,我将从数据库中获取的值定制为问题和答案。在这里,我不知道如何动态传递anItemCorrect值:

<script>
  $('#tutorial-fillblank').quizyFillBlank({
    textItems:[<?php foreach($question as $article)  { echo "'".$article->question."',";}?>],
    anItems:[<?php foreach($question as $article)
    {$a[]=$article->answer;}
    $arr=$a; shuffle($arr); foreach($arr as $ans => $val) {echo "'".$val."',";} ?> ], 
    anItemsCorrect:[<?php foreach($arr as $ans => $val) { echo "'".$ans."',";} ?>],
    blockSize:150
  });
</script>

$(“#教程填充空白”).quizyFillBlank({

textItems:[你不能这样做,因为你把你的问题乱排,所以你不知道答案的顺序


与其这样做,不如使用相关联的php数组映射question=>answer。然后您可以洗牌并保持顺序。

看看这个。我如何在这里使用相关联的php数组映射,因为我在$article->question and answers as$article->answers中获得问题,并将其作为$article->answers获得整个数组值。在这里,我如何使用关联数组