Home >>PHP Programs >PHP get max value in array
<?php //using library function $arr= array(110, 20, 52 ,105, 56, 89, 96); echo max($arr); ?>
<?php $arr= array(110, 20, 52 ,105, 56, 89, 96); //using foreach loop $b = 0; foreach ($arr as $key=>$val) { if ($val > $b) { $b = $val; } } echo $b; ?>
<?php $arr= array(110, 20, 52 ,105, 56, 89, 96); //using forloop $b = 0; for($i=0;$i<count($arr);$i++) { if ($arr[$i] > $b) { $b = $arr[$i]; } } echo $b; ?>