How to find min & max value in array without using pre-defined function ?

Code

<?php
$arr=Array(66,69,33,43,44,76,67,99,133,144,177,277,20,3,11,9,4,110);
$min=$arr[0];
$max=$min;
foreach($arr as $val)
{
if($min>$val)
$min=$val;
if($max<$val)
$max=$val;
}

echo $min,” “,$max;
?>

Output

3 277

Leave a Reply