/ *
* find the largest two-dimensional matrix (element and maximum) in a matrix
* @ param unknown $arr two-dimensional matrix
* @ param unknown $row two-dimensional matrix rows
* @ param unknown $col two-dimensional matrix columns
* @ return unknown [] []
* /
php
function test1($arr,$row,$col){
$sum0 = 0;
for ($i=0;$i<$row-1;$iPP){
for ($j=0;$j<$col-1;$jPP){
$sum1 = $arr[$i][$j]+$arr[$i][$j+1]+$arr[$i+1][$j]+$arr[$i+1][$j+1];
if ($sum1 > $sum0){
$l = $i;
$m = $j;
$sum0 = $sum1;
}
}
}
$res= array(array($arr[$l][$m],$arr[$l][$m+1]),
array($arr[$l+1][$m],$arr[$l+1][$m+1]));
return $res;
}
$arr = array(array(1,2,0,3,4),array(2,3,4,5,1),array(1,1,5,3,0));
print_r(test1($arr,3, 5));
javascript
function test1(arr,row,col){
var sum0 = l = m = 0;
for (var i=0;i<row-1;iPP){
for (var j=0;j<col-1;jPP){
var sum1 = arr[i][j]+arr[i][j+1]+arr[i+1][j]+arr[i+1][j+1];
if (sum1 > sum0){
l = i;
m = j;
sum0 = sum1;
}
}
}
var res = [[arr[l][m],arr[l][m+1]],arr[l+1][m],arr[l+1][m+1]];
return res;
}
var arr = [[1,2,0,3,4],[2,3,4,5,1],[1,1,5,3,0]];
console.log(test1(arr,3, 5));
/**
* @param $x
* @param $y
* @param $arr
* @return array value
*/
function get_max_value($x,$y,$arr){
$count=count($arr);
if($x*$y!=$count){//
return false;
}
$list=array_chunk($arr,$x);//
$max=0;//0
for($b1=1;$b1<$y;$b1PP){//y
for($a1=0;$a1<$x-1;$a1PP){//x
$s=$list[$b1-1][$a1]+$list[$b1-1][$a1+1]+$list[$b1][$a1]+$list[$b1][$a1+1];
if($s>$max){
$max=$s;
unset($max_arr);
$max_arr[]=[$list[$b1-1][$a1],$list[$b1-1][$a1+1],$list[$b1][$a1],$list[$b1][$a1+1]];
}elseif($s==$max){//
$max_arr[]=[$list[$b1-1][$a1],$list[$b1-1][$a1+1],$list[$b1][$a1],$list[$b1][$a1+1]];
}
}
}
return $max_arr;
}
$arr=[1 ,2, 0, 3, 4,
2, 3, 4, 5, 1,
1, 1, 5, 3, 0];
print_r(get_max_value(5,3,$arr));