Loading... ##php下的99乘法表的几种循环写法## <!--more--> 写的时长太久,而且记不住。 <pre> <code> <?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 "<br>"; $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 "<br>"; $k++; } echo "</table>"; echo "<br>"; echo "<br>"; 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 "<br>"; $w++; }while ($w<=9); echo "</table>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; ?> </code> </pre> 最后修改:2019-08-09 © 允許規範轉載 讚賞 讚賞作者 支付宝微信 赞 如果覺得我的文章對你有用,請隨意讚賞