PHP中的数组排序/搜索技术

PHP*_*ari 1 php arrays sorting

我有一个数组$array = array(2, 1, 8, 3, 6, 0, 10, 10),我想得到该数组的第二大值.哪种排序/搜索技术最好?我如何使用它?

Dan*_*uis 6

我只是从你的数组中删除重复项(使用array_unique),然后使用rsort(使用Quicksort)和SORT_NUMERIC标志从数字上从高到低排序:

$array = array(2, 1, 8, 3, 6, 0, 10, 10);
$unique_array = array_unique($array);
rsort($unique_array, SORT_NUMERIC);
$second_highest = $unique_array[1];  // will be 8
Run Code Online (Sandbox Code Playgroud)

PHP手册对排序技术进行比较.