Second Highest value form array in php foreach loop

 <?php


$value = [12,14,15,55,6,67];



$max=0;

$max2=0;


foreach($value as $val){

    if($val > $max){

      $max2 = $max;

      $max = $val;

    }elseif($val > $max2 && $max != $val ){

    

     $max2 =$val;

    }

}


echo $max." It is max Value </br>".$max2." It is secod max value";


?>

Comments

Popular posts from this blog

Interview question laravel.

My Sql Query ..