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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:00:17+00:00 2026-06-14T05:00:17+00:00

I have an array within an array, for example: [ [0, 20, 5], [5,

  • 0

I have an array within an array, for example:

[ 
    [0, 20, 5], 
    [5, 0, 15], 
    [5, 10, 0]
]

I need to get the max number in each column.

  • The max of [0 , 5 , 5] is 5, so that goes into the result array.
  • The max of [20, 0, 10] is 20, so that goes into the result array.
  • The max of [5, 15, 0] is 15, so that goes into the result array.

The final result array must contain [5, 20, 15].

  • 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-14T05:00:19+00:00Added an answer on June 14, 2026 at 5:00 am

    First, the array has to be transposed (flip the rows and columns):

    function array_transpose($arr) {
       $map_args = array_merge(array(NULL), $arr);
       return call_user_func_array('array_map', $map_args);
    }
    

    (taken from Is there better way to transpose a PHP 2D array? – read that question for an explanation of how it works)

    Then, you can map the max function on the new array:

    $maxes = array_map('max', array_transpose($arr));
    

    Example: http://codepad.org/3gPExrhO

    Output [I think this is what you meant instead of (5, 15, 20) because you said index 1 should be max of (20, 0, 10)]:

    Array
    (
        [0] => 5
        [1] => 20
        [2] => 15
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Knockout observable array that I wish to edit from within Javascript
I would need help: I have an array and I need to get values
I have an array within an array. $a = array ( 0 => array
Possible Duplicate: checking if pointer points within an array If I have an array
I have an array of values all well within the range 0 - 63,
I have a multidimensional array, and I would have multiple arrays within it. Some
I have lots of details. I want to stack them within an array, can
I have a several DBF files generated by a third party that I need
I have a preg_match_all that is generating an array of urls from a string.
I have a multidimensional array that looks something like this: ourThing = array( 'id'

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.