0
$array = array(
    10 => 6,
    12 => 7,
    13 => 7,
    14 => 4,
    15 => 6);

How to get the list of highest values in the above array? I need index 12 and 13 Any ideas?

4
  • 1
    "highest" is a superlative degree. How can the index 12 be qualified to be the highest index? Commented Nov 5, 2014 at 10:04
  • PHP has a built-in function to extract the one element that has the highest value - you'll have to add some of your own logic in order to extract more than one if they are the same value. Why not try to implement this yourself and then come back with some more details if you are still having problems. Commented Nov 5, 2014 at 10:04
  • max($array); return the higher value in that array, but one value :) Commented Nov 5, 2014 at 10:06
  • $heigher = max($array); $heighVal = array(); foreach ($array as $v) { if ( $v > $heigher || $v == $heigher ) { array_push($heighVal , $v); } } print_r($heighVal); Commented Nov 5, 2014 at 10:18

1 Answer 1

1

you can use following code

$keys = array_keys($array, max($array));
echo "<pre>";
print_r($keys);
echo "</pre>";
Sign up to request clarification or add additional context in comments.

4 Comments

array_keys($array, max($array)); returned list of keys having maximum values
so you want to get values also?
No. It works as expected. I need only all the keys having maximum values.
please tick correct to accept answer if helpful

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.