如何提交答案并检查答案是否与数据库表php mysql中的答案相同?

$answers = ambilJawabanUSER($simpanID,$conn); // function to save the answer from database table
$userAnswer = $_POST['answers'];

foreach( $userAnswer as $getAnswer ) {
   if ($userAnswer == $answers){
      echo "correct";
else{
echo "wrong";
}
}

my code is similar with the code above but it didnt work in my case. anyone has the solution?

I think you have one error in code. Your should try this code

$answers = ambilJawabanUSER($simpanID,$conn); // function to save the answer from database table
$userAnswer = $_POST['answers'];

foreach( $answers as $getAnswer ) {
   if ($userAnswer == $getAnswer){
      echo "correct";
}else{
echo "wrong";
}
}