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

  • SEARCH
  • Home
  • 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 6588843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:05:54+00:00 2026-05-25T17:05:54+00:00

I have about 50 items in a list. I calculate their value using an

  • 0

I have about 50 items in a list. I calculate their value using an algorythm and I add their value in an array.

Suppose I get this when the loop is over:

$vals = (51, 23, 77, 3, 8, 31, 17, 102, 87, (...));

Now, how can I get they keys of the 3 highest values in the array?

In the above example, I would like to get:

  • 8 (key of 102)
  • 9 (key of 87)
  • 3 (key of 77)

PS: I don’t want to insert those datas in a DB and then select them with Order clause, I’m sure there is an easier way around.

  • 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-05-25T17:05:55+00:00Added an answer on May 25, 2026 at 5:05 pm
    $vals = array(51, 23, 77, 3, 8, 31, 17, 102, 87);
    arsort($vals);    
    $keys = array_slice(array_keys($vals), 0, 3);
    
    var_dump($keys); // array(3) { [0]=> int(7) [1]=> int(8) [2]=> int(2) }
    

    The result is not the same you’d like to get, because arrays in php are 0-indexed

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Ordered List which contains about 100 List Items. This ol makes
i have a question about the items in a list box. when i add
I have about 10 drop down list controls that get populated. Instead of copying/pasting
I have a list of about 500 million items. I am able to serialize
I have a List of about 20 items I want to display to the
My Task Background : I have list of data items and have to calculate/aggregate
I have a HTML list of about 500 items and a filter box above
I currently have about 650,000 items in memcached (430MB memory used) and the number
I have about 100k Outlook mail items that have about 500-600 chars per Body.
So I have a ListView with an upper limit of about 1000 items. I

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.