I made a test that sends values ​​to POST, there is also an array with the correct values, foreach processes it all. But even if in two arrays the same data, it is considered as incorrect.

$q[1]['true_answers'] = [2, 5]; if (is_array($_POST['q1'])) { $q1_request = $_POST['q1']; foreach ($q1_request as $answer) { echo $answer."\n"; } } foreach ($q[1]['true_answers'] as $ans){ echo $ans."\n"; } if($ans === $answer){ $goodq[] = "β„–1"; } else { $badq[] = "β„–1"; } 

  • one
    It is not clear why you are comparing variables outside of foritch, what's the point then to run through the array. Secondly, the variable ans and answer will contain only the last value from the array. - quaresma89
  • @ quaresma89, an array for displaying values, it displays them, and then compares and gives the final result + in order to translate arrays into ordinary variables with data. Otherwise, writes "Array" - ilya1099
  • Since now you have written, only the last elements in the arrays are compared. - Visman
  • @visman, but how will the arrays be checked completely for strict equality? - ilya1099
  • one
    Look at this php.net/manual/ru/function.array-diff-assoc.php function. - Visman

1 answer 1

Since you put strict type checking, you will not have positive comparison results. All that comes from POST and GET is all String type, and you have an array. Remove strict comparison.

  • How then to change an array? I need the test values ​​to be strictly equal to what I need, otherwise if at least one of them matches, it writes that it is correct. - ilya1099
  • Remove the strict check I tell you, secondly, compare the values ​​in the cycle and not outside. - quaresma89
  • @ ilya1099 you already decide you need a complete match of the arrays, or that at least one of the elements in your array and that came with the post coincided? - fens