Below is my javascript code! I'm trying to increment the index of array $arr everytime the user clicks a button. The array is defined in a separate php tag! Where am I going wrong?
function option1() {
var i = 0;
document.getElementById("btn0").value = "newButtonValue";
document.getElementById("question").innerHTML =
"<?php echo $arr["results"][i++]["question"] ?>";
}
var i=0is insideoption1and it is initialized to0every timeoption1is invoked.<?php echo $arr["results"][i++]["question"] ?>you are mixing an Array in the backend with an index in the frontend. The two are executed (and therefore available) at different times and on different computers.