【发布时间】:2015-06-02 17:54:40
【问题描述】:
我正在尝试用 PHP 编写一个脚本,该脚本将生成一个带有垂直字母表的表格。它会简单地回显从 A 到 Z 的字母,当涉及到 Z 时,它将重置并再次从 A 开始。我对此有疑问,因为我只能重复两次,然后所有单元格中都有一些不需要的符号。我正在使用他们的 ASCII html 代码来回显这封信,其中 A 符号是 A,Z 符号是 Z。
这是我到现在为止的代码,谢谢你的帮助。
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Vertical alphabet</title>
</head>
<body>
<form method="post">
<input type="number" placeholder="COLUMNS" name="cols" />
<input type="number" placeholder="ROWS" name="rows" />
<input type="submit" value="Create table" /><br><br>
</form>
<?php
if(isset($_POST['rows']) && isset($_POST['cols'])) {
$col = $_POST['cols'];
$row = $_POST['rows'];
echo ("<table rules='all'>");
for($i = 1; $i<$row+1; $i++) {
echo ("<tr>");
for($c = 0; $c<$col; $c++) {
$letter_id = 65;
$number = ($i + ($c*$row)-1);
$letter = $number + $letter_id;
if($letter > 90) {
$number = $number - 26;
$letter = $letter - 26;
echo ("<td>". "&#" . $letter. "</td>");
} else {
echo ("<td>". "&#" . $letter. "</td>");
}
}
echo ("</tr>");
}
echo ("</table>");
}
?>
</body>
</html>
【问题讨论】:
-
havent 真的看你的代码,但我的 arrprach 会像
foreach (range('a', 'z') as $letter) {
标签: php for-loop alphabet letter