This article mainly introduces how to use php to implement the rank function in excel. it gives a detailed analysis of the rank function functions and specific implementation methods, for more information about how to use php to implement the rank function in excel, see the following example. Share it with you for your reference. The specific analysis is as follows:
The rankings of SQL statements are as follows:
The total score is 195,180,180,161, and the ranking is 1, 2, 3, and 4 respectively. in parallel, the ranking is in order,
The rank ranking result of the Excel function is 1, 2, and 2. in the case of parallel skipping
The following function simulates this situation.
The function is as follows (I don't know if there is a better implementation method ):
Formula: Ranking = total number of people-number of smaller numbers than yourself-number of repetitions of this score + 1 (plus yourself)
The rank calculation function is implemented by writing the array with the ranking to the database based on the corresponding id.
(Of course, this can also be changed to 195,180,180,165, and the ranking is 1, 2, 3)
The code is as follows:
// Obtain an array of numbers of rankings
Function rank (array $ array ){
Foreach ($ array as $ val ){
$ Repeat = get_array_repeats ($ val, $ array );
$ Num = gt_array_values ($ val, $ array );
$ Rank [] = count ($ array)-$ num-$ repeat + 1;
}
Return $ rank;
}
// Obtain a smaller number than your own.
Function gt_array_values ($ val, array $ array ){
$ Num = 0;
For ($ I = 0; $ I If ($ val> $ array [$ I]) {
$ Num ++;
}
}
Return $ num;
}
// Obtain the number of repetitions
Function get_array_repeats ($ string, array $ array ){
$ Count = array_count_values ($ array );
Foreach ($ count as $ key => $ value ){
If ($ key = $ string ){
Return $ value;
}
}
}
I hope this article will help you with php programming.