Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8483581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:08:41+00:00 2026-06-10T20:08:41+00:00

I have a array like this array( 45=>5, 42=>4.9, 48=>5, 41=>4.8, 40=>4.9, 34=>4.9, …..

  • 0

I have a array like this

 array(
      45=>5,
      42=>4.9,
      48=>5,
      41=>4.8,
      40=>4.9,
      34=>4.9,
      .....
      )

Here index is userid and value is his score.

Now what i want is to achieve percentile for on user for example percentile of 45,48 would be 99 and 42,40,34 would be 97 and 41 would be 94.

How i can achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:08:43+00:00Added an answer on June 10, 2026 at 8:08 pm
    1. Sort the array based on the “score”, ascending
    2. Percentile = (Index of an element in the sorted array ) * 100 / (total elements in the array)

    Example:

    <?php
    $array = array(
          45=>5,
          42=>4.9,
          48=>5,
          41=>4.8,
          40=>4.9,
          34=>4.9,
          );
    
    print("Unsorted array:<br/>");
    print_r($array);
    arsort($array);
    print("<br/>");
    print("Sorted array:<br/>");
    print_r($array);
    print("<br/>");
    
    $i=0;
    $total = count($array);
    $percentiles = array();
    $previousValue = -1;
    $previousPercentile = -1;
    foreach ($array as $key => $value) {
        echo "\$array[$key] => $value";
        if ($previousValue == $value) {
        $percentile = $previousPercentile;
        } else {
        $percentile = 99 - $i*100/$total;
        $previousPercentile = $percentile;
        }
        $percentiles[$key] = $percentile;
        $previousValue = $value;
        $i++;
    }
    
    print("Percentiles:<br/>");
    print_r($percentiles);
    print("<br/>");
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array like this: int sayilar[10] = {5,6,2,1,4,2,5,5,5,2}; now I want to
I have an array like this: $a = array('aa', 'bb', 'cc', 'dd'); I want
I have an array like this array={'a'=>'2','b'=>'5', 'c'=>'6', 'd'=>'6', 'e'=>'2'}; The array value might
I have a array like this: my @arr = (Field3,Field1,Field2,Field5,Field4); Now i use map
I have array like this: $test = array(20, 30, 40); And I want to
I have array like this: $test = array(20, 30, 40); And I want to
Let's say I have an array like this: string x[2][55]; If I want to
I have an array like this. int image[] = {R.drawable.d002_p001,R.drawable.d002_p002,R.drawable.d002_p003, R.drawable.d002_p004,R.drawable.d002_p005,R.drawable.d002_p006}; Right now I
I have an array like this: [234, 235 , 343, 445] I want to
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.