Due to specific work reasons,I made a paper questionnaire,The main content of the questionnaire is to allow users to prioritize the item requirements (numbered a, b ...),So I get hundreds of results similar to a>i>h>g>d .... and so on.


Quantitatively evaluate this requirement based on the ranking results of users,The final result hopes to be a :, b :, c:..... to find out which element is relatively important,Others are relatively unimportant.


According to the ranking of the number,Assign different weights,Count all the results,These weights are aggregated.For example:the result "abcdefghij" means that the item a is scored,j got points for this,d This score was scored.

Knowledge points:

File readingLoop;associative array;Sort the array.

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

Note:file.txt is a text file,Each of these lines represents the results of a questionnaire,Something like "abcdefghij".How did you get this file?Okay, I admit it was n’t manually entered by myself,I asked for help