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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:27:18+00:00 2026-06-10T14:27:18+00:00

This is my problem: I need to get four members of an array that

  • 0

This is my problem:
I need to get four members of an array that have the maximum values of an attribute. I have seen the max() function already, but that one only gets me one member, and I need four. For example, I can have an array like this:

array( 
    array(
        "1", 
        "10"
    ), 
    array(
        "9", 
        "10"
    ), 
    array(
        "3", 
        "10"
    ), 
    array(
        "4", 
        "10"
    ), 
    array(
        "10", 
        "10"
    ), 
    array(
        "8", 
        "10"
    ), 
    array(
        "7", 
        "10"
    ), 
    array(
        "6", 
        "10"
    ), 
    array(
        "5", 
        "10"
    ), 
    array(
        "9", 
        "10"
    ) 
)

I need a function that will get me these four members:

array(“10”, “10”), array(“9”, “10”), array(“8”, “10”), array(“7”,
“10”)

Can anyone help?

  • 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-10T14:27:20+00:00Added an answer on June 10, 2026 at 2:27 pm

    Sort the array via usort() in descending order.
    Pick the first four items via array_slice

    <?php
    $ar = getData();
    usort( $ar, function($a,$b) { return -strnatcmp($a[0], $b[0]); });
    $result = array_slice($ar, 0, 4);
    var_dump($result);
    
    function getData() {
        return array(
            array("1", "10"),
            array("9", "10"),
            array("3", "10"),
            array("4", "10"),
            array("10", "10"),
            array("8", "10"),
            array("7", "10"),
            array("6", "10"),
            array("5", "10"),
        );
    }
    

    prints

    array(4) {
      [0]=>
      array(2) {
        [0]=>
        string(2) "10"
        [1]=>
        string(2) "10"
      }
      [1]=>
      array(2) {
        [0]=>
        string(1) "9"
        [1]=>
        string(2) "10"
      }
      [2]=>
      array(2) {
        [0]=>
        string(1) "8"
        [1]=>
        string(2) "10"
      }
      [3]=>
      array(2) {
        [0]=>
        string(1) "7"
        [1]=>
        string(2) "10"
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem that I need guidance with. I have an array that
I need some help in solving this problem. We have a large amount of
I bumped into this problem when I created a chart that need a axis
Ive got this problem: Line 20 (LOOT_FromContainer(container) I need that to use as Invoke
I have solved this problem, I just need to know what to do. I
Need some help with this problem in implementing with XSLT, I had already implemented
I'm trying to debug this problem but not sure where exactly i need to
I've been researching this problem, but I can't find what I need. It shouldn't
Well i need some help here i don't know how to solve this problem.
I don't like JSF but I need to solve this problem with it, 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.