I am creating a quiz with PHP. I have an answer key array and then I am building another array based on the user's answers. I want to compare both arrays and determine how many array values match the answer key array. I am currently using array_intersect() but this function doesn't seem to care about the index of the array values.
$user_answers = array(1,3,1);
$answer_key = array(3,1,1);
$result = array_intersect($user_answers, $answer_key);
echo count($result);
This returns 3, but I want it to return 1. How can I make it so that array_intersect is dependent on the index of the array values?