php 使用php创建乘法表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21968849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
creating multiplication table using php
提问by Evgeniy Kleban
I'm trying to create multiplication table using php as follows:
我正在尝试使用 php 创建乘法表,如下所示:
<?php
$cols = 10;
$rows = 10;
?>
... lot of html code ...
... 很多 html 代码 ...
<?php
echo "<table border=\"1\">";
for ($r =0; $r < $rows; $r++){
echo('<tr>');
for ($c = 0; $c < $cols; $c++)
echo( '<td>' .$c*$r.'</td></tr>');
}
echo("</table>");
?>
I probably miss something but can't figure out what is it.
我可能会错过一些东西,但无法弄清楚它是什么。
Any advices would be appreciated, thanks!
任何建议将不胜感激,谢谢!
回答by Awlad Liton
try this:
尝试这个:
you are closing tr tag for each column. you need to close tr tag after cloumn for loop.
您正在关闭每列的 tr 标签。您需要在 cloumn for 循环后关闭 tr 标签。
echo "<table border=\"1\">";
for ($r =0; $r < $rows; $r++){
echo'<tr>';
for ($c = 0; $c < $cols; $c++)
echo '<td>' .$c*$r.'</td>';
echo '</tr>'; // close tr tag here
}
echo"</table>";
回答by Kermit
Move the </tr>tag to outside the inner forloop:
将</tr>标签移到内for循环之外:
echo "<table border=\"1\">";
for ($r =0; $r < $rows; $r++){
echo('<tr>');
for ($c = 0; $c < $cols; $c++)
echo( '<td>' .$c*$r.'</td>');
echo('</tr>');
}
echo("</table>");

