如何在PHP中将for循环的输出显示为表?


How do I display the output from for loop as a table in PHP

我的输出是2d数组的形式。我上传了一个示例文件,输出显示为一个段落。我希望它以表格的形式显示。

代码:

<?php
require("reader.php"); // php excel reader
$file="sample.xls";
$connection=new Spreadsheet_Excel_Reader(); // our main object
$connection->read($file);
$startrow=1;
$endrow=1000;
for($i=$startrow;$i<$endrow;$i++){ // we read row to row
    for($j=1;$j<=30;$j++) {
        // so we get [2][3] and [3][3]
        echo $connection->sheets[0]["cells"][$i][$j]; 
        echo "'n";
    }
    echo "'n";
}
?>

试试这个:

echo "<table>";
for($i=$startrow;$i<$endrow;$i++){ // we read row to row
   echo "<tr>";
    for($j=1;$j<=30;$j++) {
        echo "<td>";
        echo $connection->sheets[0]["cells"][$i][$j]; 
        echo "</td>";
    }
  echo "</tr>";
}
echo "</table>";