找出数组中三个最大的数 (PHP)

Find three greatest numbers of an array (PHP)

我需要知道如何找到数组中最大的三个数。目前我只能找到一个数组的最大数,但我想拥有其中最大的三个:

$avg = array();
$avg[20,10,30,50,80,90,220];
echo max($avg);

也许你能帮我这个忙?

// The array
$avg = [20,10,30,50,80,90,220];
// remove duplicates if any
$avg = array_unique($avg);
// sort in descending order
rsort($avg);
// get the first three elements
$avg = array_slice($avg, 0, 3);

Demo