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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:21:14+00:00 2026-06-02T21:21:14+00:00

I have an array with these values: Array ( [0] => Array ( [0]

  • 0

I have an array with these values:

Array
(
    [0] => Array
    (
        [0] => John
        [1] => 2012-03-29
        [2] => 1
    )
    [1] => Array
    (
        [0] => Doe
        [1] => 2012-03-30
        [2] => 1
    )
    [2] => Array
    (
        [0] => John
        [1] => 2012-03-31
        [2] => 2
    )
    [3] => Array
    (
        [0] => Doe
        [1] => 2012-03-31
        [2] => 5
    )
    [4] => Array
    (
        [0] => John
        [1] => 2012-04-02
        [2] => 5
    )
    [5] => Array
    (
        [0] => John
        [1] => 2012-04-02
        [2] => 21
    )
)

I’m trying to get the maximum value of array[][2] for each date in array[][1].

For example, in the array

Array[2][1] = 2012-03-31 | Array[2][2] = 2
Array[3][1] = 2012-03-31 | Array[3][2] = 5

Out of those two same days I want to keep Array[3] and discard Array[2].

I tried a foreach function:

foreach ($days as $k) {
    $max_vals[] = array($k[0], $k[1], max($k[2]));
}

But found that is not working with the days. How can I sort this array keeping the highest value for each day, and discard the rest?

  • 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-02T21:21:20+00:00Added an answer on June 2, 2026 at 9:21 pm

    The following code will iterate across each value in $data, either added newly encountered dates to the $cache or checking if it is larger.

    $cache = array();
    // Note: $data is the array you provided above, replace with your variable name.
    foreach ($data as $k => $v) {
      if (isset($cache[$v[1]])) {
        if ($cache[$v[1]] < $v[2]) {
          $cache[$v[1]] = $v[2];
        }
      } else {
        $cache[$v[1]] = $v[2];
      }
    }
    

    When finished, $cache will be an array with the values being dates and the keys the max value of array[][2].

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

Sidebar

Related Questions

I have these code in my views.py: array = [] p = Person.objects.filter(client=1,status='Complete').values('name', 'age',
I have a function which accepts some values as char array[] parameters. These values
I have an array with these values: array 0 => array 0 => int
I have an array containing some values and I want to get their sum.
I have a array with a variable amount of values. Is there a more
I have an array of integers like these; dim x as integer()={10,9,4,7,6,8,3}. Now I
I have a array of names and I want to use these names for
I have an array with 16 elements. I would like to evaluate these to
I have an array of pointers to Objective-C objects. These objects have a sort
I have an array made of unlimited number of objects. These objects have the

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.