0

I want to know how to get the array index values dynamically.

Here I am customizing the quizy-fillintheblanks.master.zip files used in my coding:

<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>

In above coding textItems are questions and anItems are answers, and anItemCorrect is the array index value for anItems.

In that coding I am customizing values I'm getting from a database into questions and answers. Here I don't know how to pass anItemCorrect value dynamically:

<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>

How can I use jquery.inArray() to dynamically choose whether an answer is right or wrong?

Adi Inbar
  • 12,097
  • 13
  • 56
  • 69
Anne Tina
  • 13
  • 1
  • 2
  • 8

1 Answers1

0

You can't, because you shuffle your questions, so you don't know what order the answers are in.

Instead of doing that, use an associated php array mapping question=>answer. Then you can shuffle and order will be maintained.

pfrank
  • 2,090
  • 1
  • 19
  • 26
  • How could I use associative php array mapping here because i am getting questions in $article->question and answers as $article->answers getting whole array values. In this how could i use associative array – Anne Tina Sep 02 '13 at 06:48