PHP: find minimum and maximum number using for loop in php

Find a minimum number given number--
Some number given in an array.Firstly for loop create and check $i value.
in for loop if condition check that is $ab[$i] is less then $minimum.
Next store value of $ab[$i] in $minimum.

<?php
 $ab=array(88,66,6,10,45,47,5);
 $minimum=array(0);
 for($i=0;$i<count($ab);$i++)
 {
  if($ab[$i] < $minimum)
 {
  $minimum=$ab[$i];
 }
 }
  echo "minimum number is $minimum";
?>


Find a maximum number given number
Same if get maximum number.Only change in if condition.


<?php
 $ab=array(5,88,4,1,66,7,3,11,45);
 $highnum=0;
 for($i=0;$i<count($ab);$i++)
 {
 if($ab[$i] > $highnum)
 {
 $highnum=$ab[$i];
 }
 }
 echo $highnum;

?>

Labels: