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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:45:04+00:00 2026-05-13T23:45:04+00:00

I am working on a display screen for our office, and I can’t seem

  • 0

I am working on a display screen for our office, and I can’t seem to think of a good way to find the largest numerical value in a set of data in a two dimensional array. I’ve looked at using max() and also asort() but they don’t seem to cope with a two dimensional array.

I’m returning my data through our mysql class, so the rows are returned in a two dimensional array.

Array(
 [0] => Array(
  [am] => 12,
  [sales] => 981),
 [1] => Array(
  [am] => 43,
  [sales] => 1012),
 [2] => Array(
  [am] => 17,
  [sales] => 876)
)

I need to output a class when foreaching the data in my table for the AM with the highest sales value. Short of comparing them all in > if statements. I have tried to get max() on the array, but it returns an array, as it’s look within the dimension. When pointing it at a specific dimension it returns the key not the value.

I figured that I could asort() the array and pop the top value off, store it in a variable and then compare against that in my foreach() loop, but that seems to have trouble sorting across two dimensions.

Lastly, I figured that I could foreach() the values, comparing them against the previous one each time, untill I found the largest. This approach however means storing every value, luckily only three, but then comparing against them all again.

Surely there must be a simpler way to achieve this, short of converting it into a single dimension array, then doing an asort() on that?

  • 1 1 Answer
  • 1 View
  • 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-13T23:45:04+00:00Added an answer on May 13, 2026 at 11:45 pm
    <?php
    function customSort($a, $b)
    {
        if($a['sales'] == $b['sales'])
            return 0;
        else
            return $a['sales'] < $b['sales'] ? -1 : 1;
    }
    
    usort($array, 'customSort');
    ?>
    

    Is what I would do

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

Sidebar

Related Questions

I'm using the following in order to have on screen display of each value
I am working with small application for display bubbles images on android screen.I have
At the moment I am working on an on screen display project with black,
Currently I'm working on to display Epub content in UIWebview . From this link
REASON: I'm working on an emergency alert application that needs to display information on
I am working on a program that uses IE to display its help pages.
in F# interactive:how to display/change current working directory?
I am working on a windows application where i want to display orkut user
I'm working on a LaTeX document and using lstlisting to display my Java source
I'm working on an ASP.Net project to display information on a website from a

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.