php statistics on questionnaire results, php questionnaire results statistics_PHP tutorial

WBOY
Release: 2016-07-12 09:07:44
Original
1140 people have browsed it

php statistics of questionnaire results, php questionnaire results statistics

Background:

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

Target:

Conduct a quantitative evaluation of these 10 requirements based on the user's ranking results. The final result is expected to be A: 78, B: 68, C: 70... to find out which element is relatively important and which one is more important. Some 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 10 points, item J gets 1 point, and item D gets 7 points.

Knowledge points:

File reading; looping; associative array; array sorting.

php code:

<span> 1</span> <span>$rs</span> =<span>array</span>("A"=>0,"B"=>0,"C"=>0,"D"=>0,"E"=>0,"F"=>0,"G"=>0,"H"=>0,"I"=>0,"J"=>0<span>);
</span><span> 2</span> <span>$handle</span> = <span>fopen</span>('./file.txt', 'r'<span>);
</span><span> 3</span> <span>while</span>(!<span>feof</span>(<span>$handle</span><span>))
</span><span> 4</span> <span>{
</span><span> 5</span>     <span>$string</span> = <span>fgets</span>(<span>$handle</span>, 1024<span>);
</span><span> 6</span>     <span>for</span>(<span>$i</span>=0;<span>$i</span><<span>strlen</span>(<span>$string</span>);<span>$i</span>++<span>)
</span><span> 7</span> <span>    {
</span><span> 8</span>         <span>$t</span> = <span>strtoupper</span>(<span>$string</span>[<span>$i</span><span>]);
</span><span> 9</span>         <span>if</span>(<span>isset</span>(<span>$rs</span>[<span>$t</span><span>]))
</span><span>10</span>             <span>$rs</span>[<span>$t</span>] = <span>$rs</span>[<span>$t</span>]+ <span>strlen</span>(<span>$string</span>) - <span>$i</span><span>;
</span><span>11</span> <span>    }
</span><span>12</span> <span>}
</span><span>13</span> <span>fclose</span>(<span>$handle</span><span>);
</span><span>14</span> <span>arsort</span>(<span>$rs</span><span>);
</span><span>15</span> <span>var_dump</span>(<span>$rs</span>);
Copy after login

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)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1059470.htmlTechArticlephp Statistics of questionnaire results, php questionnaire results statistical background: Due to specific work reasons, I made a A paper questionnaire. The main content of the questionnaire is to ask users to answer 10 items...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!