0

我刚开始使用PHP,并尝试设计一个简单的代码,在其中定义一些随机生成的多维整数数组并将它们显示到网页上。

但是,当我尝试访问Apache.php提供的服务时,Web 浏览器不显示该网页。我的代码中缺少什么?

<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>
4

2 回答 2

4
foreach($matrix as $row =$rValue)

应该是(在两行)

foreach($matrix as $row => $rValue)

你只是得到一个白页吗?也许您应该确保 error_reporting 已打开。

http://php.net/manual/en/function.error-reporting.php

于 2013-08-21T21:59:14.447 回答
1

您是否正在运行可以实际为 PHP 页面提供服务的服务器?例如阿帕奇?如果没有,请查看此页面: * http://www.apachefriends.org/en/xampp.html跨平台;

于 2013-08-21T22:04:14.007 回答