Jump to content

Search the Community

Showing results for tags 'compare array elements'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. Hi I have these codes that try to compare content of array elements and add 1 for every similar comparison and zero for otherwise. But my codes seem not to be computing the final score, what could be the problem with my codes? Here are the codes: < <html> <head> <title>Chosen Answers</title> </head> <body> <pre> <?php error_reporting(E_ALL); ini_set('display_errors', '1'); //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")); trim($fileContents); fclose($openFile); $delimiter = " "; $myArray = explode($delimiter, $fileContents); $myArray_trimmed = array_map('trim', $myArray); print_r($myArray); echo '*' . $answers[0] . '*' . $myArray[0] . '*'; $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> > What might be wrong with my codes? Thank you
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.