生成1到N的乘法表 - HTML 表单与循环控制
<table>
    <thead>
        <tr>
            <th></th>
            <th>1</th>
            <th>2</th>
            <th>3</th>
            <th>4</th>
            <!-- Add more columns as needed -->
        </tr>
    </thead>
    <tbody>
        <?php
        if ($_SERVER["REQUEST_METHOD"] == "GET") {
            if (isset($_GET['number'])) {
                $n = $_GET['number'];
                for ($i = 1; $i <= $n; $i++) {
                    echo "<tr>";
                    echo "<th>$i</th>";
                    for ($j = 1; $j <= $n; $j++) {
                        echo "<td>" . $i * $j . "</td>";
                    }
                    echo "</tr>";
                }
            }
        }
        ?>
    </tbody>
</table>

原文地址: https://www.cveoy.top/t/topic/pcpG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录