问题:
我希望获得在多维数组中最重新复制的数组。这次谷歌没有帮助。
示例数组:
Array
(
[1] => Array
(
[iata] => HAV
[lat] => 22.9892
[lng] => -82.4091
)
[2] => Array
(
[iata] => PEK
[lat] => 40.0801
[lng] => 116.585
)
[3] => Array
(
[iata] => HAV
[lat] => 22.9892
[lng] => -82.4091
)
)
期望的输出:
Array
(
[iata] => HAV
[lat] => 22.9892
[lng] => -82.4091
)
答案 0 :(得分:1)
以这种方式:
$count = array_count_values(array_column($array, 'iata'));
arsort($count);
$result = array_column($array, null, 'iata')[key($count)];
iata
值的数组并计算这些值iata
值索引的数组数组(它们将是唯一的)并获取具有最高iata
计数值的键的数组