17 May, 2010

maximum value from an array

Finding maximum value from an array using php is quite simple. Following code finds the maximum value from an array.

$maxValue = $resultArr[0];
foreach($searchArr as $val) {
//check for all the values for maximum value and compare it with default value
if($val["total_points"] > $maxPoint) {
$maxPoint = $val["total_points"];
}
}
echo "Maximum value is:".$maxValue;
?>
//Similarly minimum value in an array can also be found just by changing the if condition

No comments: