简体   繁体   中英

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

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);
krsort($array);
ksort(array_unique($array);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM