Home >>PHP Programs >Find Minimum value of an array

Find Minimum value of an array

How to find minimum value of an array.

foreach($arr as $x)
echo "Minimum value of array = ".$temp;


First create an array with some numeric value. Now create a temporary variable $temp in which stored array's first index's value i.e 100. Now to display/fetch array's all value from start to end used foreach loop. Inside foreach create a temporary variable $x which holds array values. Now add a condition in body of foreach to check $x is less than $temp then assign $x value to $temp variable this process will contiue till end of array. after completion of foreach loop $temp variable has minimum value from array $arr. Now print mininum value.

No Sidebar ads