Home >Backend Development >PHP Tutorial >PHP questionnaire survey result statistics, PHP questionnaire survey statistics_PHP tutorial

PHP questionnaire survey result statistics, PHP questionnaire survey statistics_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:07:54860browse

php questionnaire results statistics, php questionnaire statistics

Background:

Due to specific work reasons, I made a paper questionnaire. The main content of the questionnaire is to let users prioritize their requirements (numbered A, B...), so I The results obtained are hundreds of results similar to A>I>H>G>D.... etc.

Target:

Conduct a quantitative evaluation of this requirement based on the user's ranking results. The final result is expected to be A:, B:, C:... to find out which elements are relatively important and others are relatively unimportant. .

Method:

Based on the ranking of the numbers, assign different weights, count all the results, and summarize these weights. For example: The result "ABCDEFGHIJ" means that item A gets points, item J gets points, and item D gets points.

Knowledge points:

File reading; looping; associative array; array sorting.

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);

Explanation: file.txt is a text file, each line of which represents the results of a questionnaire, similar to something like "ABCDEFGHIJ". How did you get this file? Okay, I admit that I didn’t enter it manually. I asked some people to help me (why not do an online questionnaire? Save me so much trouble)

The above content is the statistics of the PHP questionnaire survey results introduced to you in this article. I hope it will be helpful to everyone.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1058149.htmlTechArticlephp questionnaire survey results statistics, php questionnaire survey statistics background: Due to specific work reasons, I made a paper A qualitative questionnaire. The main content of the questionnaire is to ask users to express their requirements...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn