PHP statistics on the results of the questionnaire

Source: Internet
Author: User
Tags array sort
Background:

As a result of the specific work, I made a paper questionnaire, the main content of the questionnaire is to allow users to 10 requirements (numbered A, b ...). ) to prioritize, so I get a good hundreds of copies similar to A>i>h>g>d .... and other results.

Goal:

Based on the user's sequencing results, these 10 requirements were quantified and the final result would be a:78,b:68,c:70 ... to find out which one is relatively important, while others are relatively unimportant.

Practice:

According to the number of ranked position, to assign a different weight, statistics all the results, the weights are summarized. For example, the result of "Abcdefghij" indicates that A has 10 points, J has 1 points and D has 7 points.

Knowledge Points:

file read; loop ; associative array; array sort.

PHP Code:

1$rs=Array("A" =>0, "B" =>0, "C" =>0, "D" =>0, "E" =>0, "F" =>0, "G" =>0, "H" =>0, "I" =>0, "J" =>0);2$handle=fopen('./file.txt ', ' R ');3 while(!feof($handle))4{5$string=fgets($handle, 1024);6 for($i= 0;$i<strlen($string);$i++)7    {8$t=Strtoupper($string[$i]);9if(isset($rs[$t]))Ten$rs[$t] =$rs[$t]+strlen($string) -$i; One    } A} -fclose($handle); -Arsort($rs); theVar_dump($rs);

Description: File.txt is a text file in which each line represents the result of a questionnaire, similar to something like "Abcdefghij". How did this file get out? Well, I admit that I did not manually input it, I found some people to help (why not do online questionnaires?) Save this trouble)

The above on the introduction of the questionnaire results of PHP statistics, including the content of the loop, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.