我正在编写下面的PHP脚本,我想通过使用php变量设置td高度和列,我无法弄清楚如何做。任何提示和帮助,以帮助我解决它非常感谢。谢谢。
<?php
$n = 5;
$table_height = 100;
?>
<!DOCTYPE html>
<html>
<head>
<title>Your Table is Ready</title>
</head>
<body>
<table>
<?php for ($i = 0; $i < $n; $i++): ?>
<tr>
<?php for ($x = 0; $x < $n; $x++): ?>
<td height="{$table_height}"; width = "{$n}"><?php print($i * $x) ?></td>
<?php endfor ?>
</tr>
<?php endfor ?>
</table>
</body>
</html>
答案 0 :(得分:1)
更改
<td height="{$table_height}";...>
要
<td height="<?= $table_height ?>px";...>
您可能需要对单元格宽度执行相同操作。 {$var}
实际上并不打印PHP值。您需要使用php括号<?= ?>
来回显。