TzuHsing Su

php下的99乘法表的几种循环写法
php下的99乘法表的几种循环写法
扫描右侧二维码阅读全文
11
2018/09

php下的99乘法表的几种循环写法

php下的99乘法表的几种循环写法

写的时长太久,而且记不住。

 
    <?php
    header("Content-Type: text/html;charset=utf-8");
    function se(){
        echo "<h2>使用for循环生成的99乘法表</h2>";
        echo "<table border='1px', width='600'>";
        echo "<tr>".'<th colspan="9">99乘法表</th>'."</tr>";
        for ($i=1; $i <=9 ; $i++) { 
            # code...
            echo "<tr>";
            for ($j=1; $j <=$i; $j++) { 
                # code...
                echo "<td>".$j."*".$i."=".$j*$i." "."</td>";
            }
            echo "</tr>";
        }
        echo "</table>";
    }
    se();



    function sed($kk){

        echo $kk*2;

    }
    sed(22);

    echo "<h2>使用while循环生成的99乘法表</h2>";


    // echo "
"; $k=1; echo "<table border='1px', width='600'>"; echo "<tr>".'<th colspan="9">99乘法表</th>'."</tr>"; while ($k <= 9) { # code... $a=1; echo "<tr>"; while ($a <= $k) { # code... echo "<td>".$a."*".$k."=".$a*$k." "."</td>"; // echo $a."*".$k."=".$k*$a." "; $a++; } echo "</tr>"; echo "
"; $k++; } echo "</table>"; echo "
"; echo "
"; echo "<h2>使用do while循环生成的99乘法表</h2>"; echo "<table border='1px', width='600'>"; echo "<tr>".'<th colspan="9">99乘法表</th>'."</tr>"; $w=1; do { # code... $q=1; echo "<tr>"; do{ // echo $q." "; echo "<td>".$q."*".$w."=".$q*$w." "."</td>"; $q++; }while ($q <= $w); echo "</tr>"; echo "
"; $w++; }while ($w<=9); echo "</table>"; echo "
"; echo "
"; echo "
"; echo "
"; echo "
"; echo "
"; ?>
最后修改:2019 年 08 月 09 日 07 : 50 PM
如果覺得我的文章對你有用,請隨意讚賞

發表評論