The two arrays does not compare and compute by adding one for every similar and 0 if otherwise I don't know what is wrong with the codes, but to me is seems fine. What might be the problem?

<html>
<head>
<title>Chosen answers</title>
</head>
<body>
<pre>
<?php
//Posting of the chosen answers

$answers = $_POST['selected_answers'];
echo '<b><u>THE ANSWERS YOU HAVE CHOSEN ARE:</u></b><br /><br />';
print_r($answers);

//Opening of the answers file, reading and printing it

$openFile = fopen("answers.txt", "r") or exit ("unable to open the answers file");
$fileContents = fread($openFile, filesize("answers.txt"));
fclose($openFile);
$delimiter = "  ";
$myArray = explode($delimiter, $fileContents);

$score = $score1 = $score2 = $score3 = $score4 = $score5 = $score6 = $score7 = $score8 = 0;

//Computation of marks scored for the answered questions

if ($answers[0] == $myArray[0])
{
    $score = 1;
}
if ($answers[1] == $myArray[1])
{
    $score1 = 1;
}
if ($answers[2] == $myArray[2])
{
    $score2 = 1;
}
if ($answers[3] == $myArray[3])
{
    $score3 = 1;
}
if ($answers[4] == $myArray[4])
{
    $score4 = 1;
}

if ($answers[5] == $myArray[5])
{
    $score5 = 1;
}

if ($answers[6] == $myArray[6])
{
    $score6 = 1;
}

if ($answers[7] == $myArray[7])
{
    $score7 = 1;
}
if ($answers[8] == $myArray[8])
{
    $score8 = 1;
}

$Total = $score + $score1 + $score2 + $score3 + $score4 + $score5 + $score6 + $score7 + $score8 ;
echo '<br />';
echo "<b><u>$Total</u></b>";
?>
</pre>
</body>
</html>
Member Avatar for diafol

have a look at your other thread, I deal with this issue there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.