Skip to main content
The 2024 Developer Survey results are live! See the results

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 1
    If you don't need the whole array sorted, use one of the gazillion other answers obviously ;) But mentioning sort() made me think you phrased your question wrong.
    – Jacob
    Commented Jul 13, 2011 at 9:43
  • Jacob is right - doing an asort will reorder the array lowest to highest maintaining keys...then do a foreach and the $key=>$value from that will be set to the highest pair after the foreach completes..so you have the highest one right there - the key and the value... Commented Aug 23, 2019 at 0:06
  • If we use sort() or asort() it may lead to time complexity with n nodes
    – chandru
    Commented Nov 15, 2021 at 16:35
  • @chandru Which is good or bad? Commented Aug 5, 2022 at 11:31
  • 1
    @Stranger ...which is not necessary for this question/page. A loop (instead of sorting) will be "linear" and therefore will boast better performance. Commented Jan 10, 2023 at 0:50