我刚开始使用 PHP 并尝试设计一个简单的代码,我在其中定义了一些随机生成的多维整数数组,并将它们显示到网页中。
但是,当我尝试访问 Apache 所服务的.php
时,网络浏览器不会显示网页。我的代码中缺少什么?
<html>
<head>
<title>
Novatos del PHP
</title>
</head>
<body>
<?php
$m1 = array ( array (rand(0,100), rand(0,100), rand(0,100)),
array (rand(0,100), rand(0,100), rand(0,100)),
array (rand(0,100), rand(0,100), rand(0,100)),
array (rand(0,100), rand(0,100), rand(0,100))
);
$m2 = array ( array (rand(0,100), rand(0,100), rand(0,100)),
array (rand(0,100), rand(0,100), rand(0,100)),
array (rand(0,100), rand(0,100), rand(0,100)),
array (rand(0,100), rand(0,100), rand(0,100))
);
printMatrix($m1);
function printMatrix($matrix){
echo "<table width=\"200\" border=\"1\">";
foreach($matrix as $row =$rValue){
echo "<tr>";
foreach($rValue as $col =$cValue){
echo "<td>".$cValue."</td>";
}
echo "</tr>";
}
echo "</table>";
}
?>
</body>
</html>
答案 0 :(得分:4)
foreach($matrix as $row =$rValue)
应该是(在两行上)
foreach($matrix as $row => $rValue)
你刚看到白页吗?也许你应该确保启用error_reporting。
答案 1 :(得分:1)
您是否正在运行可以实际为PHP页面提供服务的服务器?例如。 Apache的? 如果没有,请查看此页面: * http://www.apachefriends.org/en/xampp.html跨平台;