Answers for "how to find largest number in array in php"

PHP
1

program logic for second largest number in an array in php

function secondHighest(array $arr) {
    
    sort($arr);
    
    echo $arr[sizeof($arr)-2];
}
 
 
secondHighest(array( 4, 9, 5, 2, 8, 0, 3, 22));
Posted by: Guest on February-08-2021
-2

find largest element of an array in php

<?php 
$array = array(5,7,81,0,12);

$max1 =0 ;
$max2 = 0;

for($i=0; $i $max1)
    {
      $max2 = $max1;
      $max1 = $array[$i];
    }
    else if($array[$i] > $max2)
    {
      $max2 = $array[$i];
    }
}
echo "Maximum value = ".$max1;
echo "
"; 
echo "Second maximum Value =".$max2;
?>
Posted by: Guest on July-29-2020

Code answers related to "how to find largest number in array in php"

Browse Popular Code Answers by Language