function thirdMax($nums) {
$nums = array_unique($nums); // built-in function that removes duplicated values in array
sort($nums);
$count = count($nums);
if ($count >= 3) {
array_pop($nums);
array_pop($nums);
}
return end($nums); // built-in function that returns the last element of array
}
echo thirdMax([2, 2, 3, 1]);