i am working with jquery ajax call and want to loop some answers with for loop. the code is look like
$answer1 = "yes";
$answer2 = "yes2";
$answer3 = "yes3";
$answer4 = "yes4";
$answer5 = "yes5";
$que_no = $_POST['que_no'];
$ans = $_POST['ans'];
if ($que_no == 1) {
if ($answer1 == $ans) {
echo "correct";
}
}
if ($que_no == 2) {
if ($answer2 == $ans) {
echo "correct";
}
}
i dont want to write this part 5 times
if ($que_no == 1) {
if ($answer1 == $ans) {
echo "correct";
}
}
if ($que_no == 2) {
if ($answer2 == $ans) {
echo "correct";
}
}
how can i loop it with for loop
i have tried $answer.$x but it will ask for the $answer variable but i dont have $answer i just want to combine it so it will be $answer1