PHP program to find the second-highest number in an array
<?php
$array = array('200', '12','69','250','50','500');
$maxnum1 = 0;
$maxnum2 = 0;
for($i=0; $i< count($array); $i++)
{
if($array[$i] > $maxnum1)
{
$maxnum2 = $maxnum1;
$maxnum1 = $array[$i];
}
else if($array[$i] > $maxnum2)
{
$maxnum2 = $array[$i];
}
}
echo "Second Maximum NO is ".$maxnum2;
?>
0 Comments