PHP Code to Find Second Largest Number in an Array
$max) { $secondMax = $max; $max = $number; } //If array number is greater than secondMax and less than max if($number > $secondMax && $number < $max) { $secondMax = $number; } } return $secondMax; } $arr = array(70, 4, 8, 10, 14, 9, 7, 6, 5, 3, 2); $second_maximum = findSecondMax($arr); echo "Second Highest Element is ".$second_maximum; ?>
0 comments:
Post a Comment
Thanks