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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:59:54+00:00 2026-05-29T08:59:54+00:00

I have a multidimensional array that looks like this: Array ( [0] => Array

  • 0

I have a multidimensional array that looks like this:

Array
(
[0] => Array
    (
        [id] => 2280764150
        [label] => Some Label A
        [pda] => 5.34
        [prt] => 67
        [kps] => 12436
        [xmv] =>  1.24
    )

[1] => Array
    (
        [id] => 2273499083
        [label] => Some Label B
        [pda] => 2.99
        [prt] => 97
        [kps] => 212436
        [xmv] =>  7.78
    )

[2] => Array
    (
        [id] => 2273045947
        [label] => Some Label C
        [pda] => 6.34
        [prt] => 157
        [kps] => 1436
        [xmv] =>  2.34
    )

)

What I would like to do is find out which array element has the max value for each of items pda prt kps and xmv. It’s not so much I want to know what the max value is, but I want to know which one has the max elements for each. So Some Label C would be logged as having max pda, Some Label B having max value for kps and so on.

I could do this with a few loops, but was looking for a more elegant solution.

  • 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-29T08:59:55+00:00Added an answer on May 29, 2026 at 8:59 am

    Here’s another one. I’m not sure if it’s elegant, though.

    $arr = array(
        array('id'=>2280764150,'label'=>'Some Label A','pda'=>5.34,'prt'=>67,'kps'=>12436,'xmv'=>1.24),
        array('id'=>2273499083,'label'=>'Some Label B','pda'=>2.99,'prt'=>97,'kps'=>212436,'xmv'=>7.78),
        array('id'=>2273045947,'label'=>'Some Label C','pda'=>6.34,'prt'=>157,'kps'=>1436,'xmv'=>2.34),
    );
    
    $max = array('pda'=>0,'prt'=>0,'kps'=>0);
    foreach (array_keys($max) as $key) {
        array_walk($arr,'get_max',$key);
    }
    
    function get_max($inner_arr,$index,$key) {
        global $max;
        if ($inner_arr[$key] > $max[$key]['max'])
        $max[$key] = array('index'=>$index,'max'=>$inner_arr[$key]);
    }
    
    print_r($max);
    

    EDIT: ABOVE CODE SHORTENED

    $max = array('pda'=>0,'prt'=>0,'kps'=>0);
    array_walk($arr,'get_max');
    
    function get_max($inner_arr,$index) {
        global $max;
        foreach (array_keys($max) as $key) {
            if ($inner_arr[$key] > $max[$key]['max'])
            $max[$key] = array('index'=>$index,'max'=>$inner_arr[$key]);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an multidimensional array that looks like this: Array ( [0] => Array
I have a multidimensional array that looks something like this: ourThing = array( 'id'
I have a multidimensional array that looks like this [0] => Array ( [recordId]
I have a multidimensional array that looks like this: Array ( [0] => Array
I have a multidimensional array that look like this: Array [1] => Array (
I have a multi-dimensional array right now that looks like this: function art_appreciation_feeds() {
I have a multi-dimensional array that looks like this: The base array is indexed
I have a multidimensional array which, when echoed in PHP, looks like this: {
I have a multidimensional array in PHP, something that looks like: array(array(Category => Video,
I have a list of recipes obtained from a database that looks like this:

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.