I have PHP code that successfully produces JSON data, but I need this output to have a structure similar to the objects shown in the JavaScript sample below. How can I loop through the JSON data and use it in JavaScript in a comparable way?
<?php
$recordSet = array();
$sqlQuery = "SELECT question_id, question_text, opt_first, opt_second, opt_third, answer_key FROM quiz_items WHERE category = 'Mathematics'";
$result = $dbConnection->query($sqlQuery);
$result->setFetchMode(PDO::FETCH_ASSOC);
while ($item = $result->fetch()) {
$recordSet['questions'][] = $item;
}
?>
const quizData = [
{ prompt: "What is 5+3?", options: [6, 8, 10, 7], correctIndex: 1 },
{ prompt: "What is 7-2?", options: [3, 4, 5, 6], correctIndex: 2 }
];