I have a quiz DB which has particular arrangement as shown below:
"question" : "What are the two binary numbers?",
"answers" : {
"ch1" : "1 and 0",
"ch2" : "1 and 2",
"ch3" : "1 to 9"
},
"rightanswer" : "ch1" }
There are n number of such entries in the DB quiz. Now I will have loop through the entire DB and print each value.
how can this can done in for loop; I'm just looking like question[i]
, answer.ch1[i]
, answer.ch2[i]
.... how to retrieve?
var-dump Results:
array(4) {
["_id"]=> object(MongoId)#7 (1) { ["$id"]=> string(24)"56bb13aef9f36fe751eecfe4" }
["question"]=> string(32) What are the two binary numbers?"
["answers"]=> array(3) {
["ch1"]=> string(7) "1 and 0"
["ch2"]=> string(7) "1 and 2"
["ch3"]=> string(6) "1 to 9"
}
["rightanswer"]=> string(3) "ch1"
}
array(4) {
["_id"]=> object(MongoId)#8 (1) { ["$id"]=> string(24) "56bb1714f9f36fe751eecfe5" }
["question"]=> string(51) "It is a standard specifying a power saving feature?"
["answers"]=> array(3) { .....
$obj["answer.ch1"]
$obj["answer.ch2"]
$obj["answer.ch3"]'); } – Puneeth Feb 10 '16 at 13:39