This article mainly introduces how to implement the rank function in excel in php. It gives a detailed analysis of the rank function functions and implementation methods. For more information, see
This article mainly introduces how to implement the rank function in excel in php. It gives a detailed analysis of the rank function functions and implementation methods. For more information, see
This example describes how to implement the rank function in excel in php. 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.