0

我试图弄清楚如何处理以这种方式排序的数组:

$countValues = array_count_values($someArray);
arsort($someArray);

我想找到符合某些标准的排序数组的第一个值。例如,你有一个包含香蕉、苹果和茶的数组。我想找到不是苹果的数组中最具代表性的成员。所以如果我们有数组:

[苹果,香蕉,苹果,香蕉,茶]

排序后会变成这样:

( [苹果] => 2 [香蕉] => 2 [茶] => 1 )

那么我如何找到不是苹果的最具代表性的价值。希望你能跟上。

谢谢。

4

1 回答 1

0
$countValues = array_count_values($someArray);
unset($countValues['apple']); // Remove apple from array.
arsort($countValues);
$most_popular = array_values($countValues)[0]; // Get first item from array (pop).
于 2013-03-30T01:27:01.343 回答