Correction status:Uncorrected
Teacher's comments:
<!-- 使用函数方法程序 --> <?php // 输入数组信息 $arr=array( [1,'候亮平',30,'男','hlp@php.cn','123456'], [2,'赵瑞龙',40,'男','zrl@php.cn','123456'], [3,'李达康',50,'男','ldk@php.cn','123456'], [4,'祁同伟',45,'男','qtw@php.cn','123456'], [5,'高小琴',30,'女','gxq@php.cn','123456'] ); $title='用户信息表'; // 统计数组元素数量 $count=count($arr); function createTable($arr){ $result=''; foreach ($arr as $v) { $result.='<tr>'; foreach ($v as $key => $value) { $result.='<td>'; if ($key==5) { $result.=sha1($v[$key]); }else{ $result.=$v[$key]; } $result.='</td>'; } $result.='</tr>'; } return $result; } ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title><?php echo $title ?></title> <style> table,th,td { border: 1px solid #666; padding: 8px; } table { border-collapse: collapse; width: 80%; text-align: center; margin: 30px auto; } thead tr:first-of-type { background-color: lightblue; } tbody tr:hover { background-color: #efefef; } table > caption { font-size: 1.2rem; margin: 15px auto; } table + p { text-align: center; } } </style> </head> <body> <table> <caption> <?php echo '<span style="color:red">' . $title . '</span>'; ?> </caption> <thead> <tr> <th>编号</th> <th>姓名</th> <th>年龄</th> <th>性别</th> <th>邮箱</th> <th>密码</th> </tr> </thead> <tbody> <?php echo createTable($arr); ?> </tbody> </table> </div> <p>总计: <?php echo $count; ?> 人</p> </body> </html>
点击 "运行实例" 按钮查看在线实例
<!-- 未使用函数封装程序 --> <?php // 输入数组信息 $arr=array( [1,'候亮平',30,'男','hlp@php.cn','123456'], [2,'赵瑞龙',40,'男','zrl@php.cn','123456'], [3,'李达康',50,'男','ldk@php.cn','123456'], [4,'祁同伟',45,'男','qtw@php.cn','123456'], [5,'高小琴',30,'女','gxq@php.cn','123456'] ); $title='用户信息表'; // 统计数组元素数量 $count=count($arr); ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title><?php echo $title ?></title> <style> table,th,td { border: 1px solid #666; padding: 8px; } table { border-collapse: collapse; width: 80%; text-align: center; margin: 30px auto; } thead tr:first-of-type { background-color: lightblue; } tbody tr:hover { background-color: #efefef; } table > caption { font-size: 1.2rem; margin: 15px auto; } table + p { text-align: center; } } </style> </head> <body> <table> <caption> <?php echo '<span style="color:red">' . $title . '</span>'; ?> </caption> <thead> <tr> <th>编号</th> <th>姓名</th> <th>年龄</th> <th>性别</th> <th>邮箱</th> <th>密码</th> </tr> </thead> <tbody> <?php $result=''; foreach ($arr as $v) { $result.='<tr>'; foreach ($v as $key => $value) { $result.='<td>'; if ($key==5) { $result.=sha1($v[$key]); }else{ $result.=$v[$key]; } $result.='</td>'; } $result.='</tr>'; } echo $result; ?> </tbody> </table> <p>总计: <?php echo $count; ?> 人</p> </body> </html>
点击 "运行实例" 按钮查看在线实例