user3025796
user3025796

Reputation: 3

php get max key from same value

How can I get max key from same value?

Example:

 1 => 32
 2 => 32
 3 => 32
 4 => 5
 5 => 5
 6 => 11
 7 => 11

Result:

 3 => 32
 5 => 5
 7 => 11

Upvotes: 0

Views: 67

Answers (2)

Dracris
Dracris

Reputation: 93

krsort($array);
ksort(array_unique($array);

Upvotes: 0

Mark Baker
Mark Baker

Reputation: 212412

Assuming values are all integer

$array = [
  1 => 32,
  2 => 32,
  3 => 32,
  4 => 5,
  5 => 5,
  6 => 11,
  7 => 11,
];

$result = array_flip(array_flip($array));
var_dump($result);

Upvotes: 2

Related Questions