Using the PHP Questionnaire survey results statistics

Source: Internet
Author: User
Tags apc module array sort
This article mainly introduces the use of PHP Questionnaire survey results Statistics, interested in the friend's reference, I hope to be helpful to everyone.

Background:

Because of the specific work, I made a paper questionnaire, the main content of the questionnaire is to allow users to request the item (number A, 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 to quantify this requirement, the final result would be a:,b:,c: ... 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 is a sub-item, j is a sub-item, and D is divided.

Knowledge Points:

file read; loop; associative array; array sort.

PHP Code:

$rs =array ("A" =>, "B" =>, "C" =>, "D" =>, "E" =>, "F" =>, "G" =>, "H" =>, "I" =>, "J"; $handle = fopen ('./file.txt ', ' R '); while (!feof ($handle)) {   $string = fgets ($handle,);   for ($i =; $i <strlen ($string), $i + +)   {     $t = Strtoupper ($string [$i]);     if (Isset ($rs [$t]))       $rs [$t] = $rs [$t]+ strlen ($string)-$i;   }} fclose ($handle); Arsort ($RS); Var_dump ($RS);

Summary : The above is the entire content of this article, I hope to be able to help you learn.

Related recommendations:

How PHP Gets the operating system type

Making an upload progress bar using PHP's APC module

Ways to filter all whitespace characters in PHP

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.