如何从相同的值获取最大密钥?
示例:
1 => 32
2 => 32
3 => 32
4 => 5
5 => 5
6 => 11
7 => 11
结果:
3 => 32
5 => 5
7 => 11
答案 0 :(得分:2)
假设值都是整数
$array = [
1 => 32,
2 => 32,
3 => 32,
4 => 5,
5 => 5,
6 => 11,
7 => 11,
];
$result = array_flip(array_flip($array));
var_dump($result);
答案 1 :(得分:0)
krsort($array);
ksort(array_unique($array);