Facebook
Banner
XMPP JavaScript Library READ MORE

Program to find second highest value from an unsorted array


1 $nums=array(5,7,6,9,1,2);
2 $max=0;
3 $sMax=0;
4 foreach($nums as $k=>$v){
5 if($v>$max){
6 $sMax=$max;
7 $max=$v;
8 }elseif($v>$sMax){
9 $sMax=$v;
10 }
11 }
12
13 echo $sMax;
Add Your Comment
   
    Yes! I want to receive all comments by email

No Comments Posted Yet. Be the first one to post comment