PHP - 在多维数组中查找最小值/最大值

Chi*_*ker 4 php

我需要在PHP中找到多维数组中的最小值和最大值,我有我认为可以在下面工作但它一直给我一个解析错误,这是功课,我不是要求任何人为我做这个但我是一个初学者和任何帮助将不胜感激.

<?php

/* 2 dimensional array in PHP - strictly an array of arrays */

$multable[] = array("11", "12", "15", "22", "41", "42");  
$multable[] = array("6", "7", "16", "17", "22", "23");  
$multable[] = array("1", "15", "16", "20", "22", "3");  


# ---------------------------------------------
?>
<html>
<head>
<title>An array of arrays in PHP</title>
</head>
<body bgcolor=white>
<h2>Two dimensional array</h2><br>
<table border=2 cellpadding=2 cellspacing=2>

<?php

/* display a table from a 2D array */
for ($j=0;$j<3;$j++) {
    print "<tr>";
    for ($k=0;$k<6;$k++) {
            echo "<td>",$multable[$j][$k],"</td>";
            }
    print "</tr>";
$max_value = 0;
foreach ($multable as $myMax) {
if ($max_value<$myMax) {
 $max_value = $myMax;
  }
}
echo $max_value;
?>
</table>
</body>
</html> 
Run Code Online (Sandbox Code Playgroud)

mar*_*rio 7

还有一个单行:

$max = max( array_map("max", $multable) );
Run Code Online (Sandbox Code Playgroud)