Blogger Information
Blog 29
fans 0
comment 0
visits 27157
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php表格生成器和九九乘法表的实现
LIWEN的博客
Original
3638 people have browsed it

1、表格生成器的实现

实现思路,用for嵌套循环实现,效果如下图:

2017-12-27_141410.png

i代码如下:

<?php
header('Content-Type: text/html; charset=utf-8');


echo <<< 'INPUT'
<form>
请输入表格的行数:<input type="text" name="row">列:<input type="text" name="col">
<button>提交</button>
</form>
INPUT;

$row = $_GET['row'];  //获取行
$col = $_GET['col'];  //获取列
echo '<table border="1" cellspacing="0" cellpadding="5" width="70%" >';  //输出表格
for($i=0;$i<$row;$i++){
    echo '<tr>';
    for ($j=0;$j<$col;$j++){
        echo '<td></td>';
    }
    echo '</tr>';
}
echo '</table>';

2、php打印九九乘法表

实现思路:for循环嵌套

实现效果:

2017-12-27_141324.png

代码如下:

<?php
header('Content-Type: text/html; charset=utf-8');

echo '<table cellspacing="0" cellpadding="5" width="500" align="center" style="margin-top: 30px">';
echo '<caption style="font-weight: bolder;color: #9A0000; font-size: 24px;">九九乘法表</caption>';

for ($i=1;$i<=9;$i++){
    echo '<tr>';
    for ($j=1;$j<=$i;$j++){
        echo '<td style="border: 1px solid #5e5e5e">'.$j.'x'.$i.'='.($i*$j).'</td>';
    }
    echo '</tr>';
}
echo '</table>';


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post