Я хочу знать, как динамически получать значения индекса массива.Как динамически передавать значение индекса массива
Здесь я настроив quizy-fillintheblanks.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>
В выше textItems кодирования вопросы и anItems приведены ответы, и anItemCorrect является значение индекса массива для anItems.
В этом кодировании я настраиваю значения, которые я получаю из базы данных, в вопросы и ответы. Вот я не знаю, как передать значение 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>
Как я могу использовать jQuery.inArray() динамически выбирать ответ, является ли правильным или неправильным?
Взгляните на это .. http://stackoverflow.com/questions/5458241/php-dynamic-array-index-name –