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 7184333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:10:48+00:00 2026-05-28T18:10:48+00:00

I have an array where the Key is the sales person. The value of

  • 0

I have an array where the Key is the sales person. The value of the key is an array, with 2 values: A percentage value, and a total value.

In a nutshell, I am trying to sort the Highest percentage value on top.

$sales = array(
    "Johnny Smith" => array(75.25,45), 
    "Ash Han" => array(55.67, 99), 
    "Janice K." => array(90.00, 40)
);

I’ve tried a few arrangements or array sorting functions, and none are good enough to even display, since they don’t have examples where the array value is an array to sort from.

The end result is where I’d like to display which sales person has the highest percentage to lowest percentage. In the case above, “Janice K.” has a percentage of 90.00, and she has 40 sales. In a nutshell, she has made 40 sales, and 90% of them have cleared.

Is it possible to sort based on the $value of a $key, if it’s an array?

  • 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-28T18:10:49+00:00Added an answer on May 28, 2026 at 6:10 pm

    uasort() sorts an array with a user-defined function and maintains index assocation. Here’s an implementation example using an anonymous function.

    uasort($sales, function($a, $b) {
        return $b[0] - $a[0];
    });
    print_r($sales);
    

    The above will yield

    Array (
        [Janice K.] => Array (
                [0] => 90
                [1] => 40
        )
        [Johnny Smith] => Array (
                [0] => 75.25
                [1] => 45
        )
        [Ash Han] => Array (
                [0] => 55.67
                [1] => 99
        )
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have an array of key/value pairs in PHP: array( 'foo' => 'bar',
i have an array which could look like this: $config[$name][$array]['key'] = 'value'; // here
Does VBA have dictionary structure? Like key<>value array?
I have array with alphanumeric key values..While filling array on particular condition I have
I have an PHP array that looks something like this: Index Key Value [0]
I have an array of key values {val1: [{gender:male}, {age:23}, {favorite-color:red}] } The thing
I have the following 'key' array: (Array 1) Array ( [0] => first_name [1]
I have this array and I need to sort it, first by key_1 and
I have array of select tag. <select id='uniqueID' name=status> <option value=1>Present</option> <option value=2>Absent</option> </select>
I have array of strings, String[] data and it's 10 elements has value P

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.