Home >>PHP Programs >PHP get highest value in multidimensional array

PHP get highest value in multidimensional array

How to get highest value from multidimensional array

Get the highest Value form multidimensional array using foreach

<?php 
//find the maximum value from two dimenstion array in php
$arr= array(array(110, 20, 52),array(105, 56, 89, 96),array( 556, 89, 96));
$b = 0;
foreach ($arr as $val)
{
	foreach($val as $key=>$val1)
	{
		if ($val1 > $b)
	 	{
        $b = $val1;
    	}
	}   	
}
echo $b;
?>

Get the highest Value form multidimensional array using for loop

<?php 
//find the maximum value from two dimenstion array in php
$arr= array(array(110, 20, 52),array(105, 56, 89, 96),array( 556, 89, 96));
$b = 0;
for($i=0;$i<count($arr);$i++)
{
	for($j=0;$j<count($arr[$i]);$j++)
	{
		if ($arr[$i][$j] > $b)
	 	{
        $b = $arr[$i][$j];
    	}
	}   	
}
echo $b;
?>