php - Compare Two Arrays based on key value -
i'm working on quiz engine , comparing answers.
i have 2 arrays
correct answers :
0 => "a" 1 => "a" 2 => "a" 3 => "c" chosen answers...
0 => "c" 1 => "b" 2 => "a" 3 => "b" so based on this, know (from comparing myself) have 1 correct answer.
is there php function can compare keys , values , increment number of similar?
i've looked @ array_intersect , array_difference don't seem give me desired answer.
thanks
short solution using array_intersect_uassoc function (on extended input arrays):
$correct = ["a", "a", "a", "c", "a", "c"]; $chosen = ["c", "b", "a", "b", "a", "b"]; $result = array_intersect_uassoc($correct, $chosen, 'strnatcmp'); print_r($result); the output:
array ( [2] => [4] => )
Comments
Post a Comment