Home >>PHP Programs >PHP get highest value in multidimensional array
<?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; ?>
<?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; ?>