Last Update - 10 Nov 2018

How to find minimum value of an array

How to find minimum value of an array

It's very simple to find the minimum value of an array using foreach loop. Create an array with some numeric value. Now create a temporary variable $temp in which stored array’s first index’s value i.e 45.

$arr=array(45,78,485,58,5,45,47);
$temp=$arr[0];
foreach($arr as $x)
{
	if($x<$temp)
	{
		$temp=$x;
	}
}

echo "Minimum value of array = ".$temp;

 

Output:

Minimum value of array = 5

More For You

Did you find this page helpful? X