Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function secondHighest($numbers)
{
$higest = -1;
$secondHighest = -1;
foreach ($numbers as $number) {
if ($higest < $number) {
$higest = $number;
}
}
foreach ($numbers as $number) {
if ($number != $higest && $secondHighest < $number) {
$secondHighest = $number;
}
}
return $secondHighest;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment