How to implement the rank function in excel using php

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.