How to Implement the rank function in excel using php

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

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.