无法增加PHP的价值

I have a function where, if the user enters the correct answer, the score should increment. The validation function is working fine, but the score is not incrementing. Initially, I defined it as 0 and then it should increment based on the answer, but it's not working.

    $score =0;
    function checkscore ($n, $ans)
    {
    global $score;
    $arr = array('a', 'd');
    if (($n == 1) && ($ans == (count(array_intersect($arr, $_POST['a'])) == count($arr))))  
    {
        $score++;
    }
    if (($n == 2) && ($ans == ($_POST['b'] == 'a'))) 
    {
        $score++;
    }

    if (($n == 3) && ($ans == "div[id='serenade']"))  
    {
        $score++;   
    }
    if (($n == 4) && ($ans != (($_POST['d1'] == 'B') && ($_POST['d2'] == 'C') && ($_POST['d3'] == 'A')))) 
    {
        $score++;   
    }

    return $score;
}

This is the function. Someone please help me.

This function will return 1 if $n is 3 or 4, 0 otherwise. The first two conditions will always be false, while the third will be true when $n==3 and the fourth when $n==4.

So it does increment occasionally, but only up to 1...