Correction status:Uncorrected
Teacher's comments:
<?php $arr = array( array( 'id' => 1, 'name' => '景天', 'age' => 16, 'sex' => '男', 'email' => 'jt@xj3.cn', 'password' => '123456' ), array( 'id' => 2, 'name' => '徐长卿', 'age' => 17, 'sex' => '男', 'email' => 'xcq@xj3.cn', 'password' => '123456' ), array( 'id' => 3, 'name' => '唐雪见', 'age' => 15, 'sex' => '女', 'email' => 'txj@xj3.cn', 'password' => '123456' ), array( 'id' => 4, 'name' => '龙葵', 'age' => 15, 'sex' => '女', 'email' => 'lk@xj3.cn', 'password' => '123456' ), array( 'id' => 5, 'name' => '紫萱', 'age' => 100, 'sex' => '女', 'email' => 'zx@xj3.cn', 'password' => '123456' ) ); $title = '用户信息表'; $tabletitle = $title; $a = count($arr) ?> <!DOCTYPE html> <html lang="en"> <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; } table > caption { font-size: 1.2rem; margin-bottom: 15px; } table + p { text-align: center; } </style> </head> <body> <table> <caption><?php echo $tabletitle ?></caption> <thead> <tr> <th>编号</th> <th>姓名</th> <th>年龄</th> <th>性别</th> <th>邮箱</th> <th>密码</th> </tr> </thead> <tbody> <?php $data =''; foreach ($arr as $ar) { $data.='<tr>'; $data.='<td>'.$ar['id'].'</td>'; $data.='<td>'.$ar['name'].'</td>'; $data.='<td>'.$ar['age'].'</td>'; $data.='<td>'.$ar['sex'].'</td>'; $data.='<td>'.$ar['email'].'</td>'; $data.='<td>'.$ar['password'].'</td>'; $data.='</tr>'; } echo $data; ?> </tbody> </table> <p>总计:<?php echo $a ?>人</p> </body> </html>
点击 "运行实例" 按钮查看在线实例
<?php $arr = array( array( 'id' => 1, 'name' => '景天', 'age' => 16, 'sex' => '男', 'email' => 'jt@xj3.cn', 'password' => '123456' ), array( 'id' => 2, 'name' => '徐长卿', 'age' => 17, 'sex' => '男', 'email' => 'xcq@xj3.cn', 'password' => '123456' ), array( 'id' => 3, 'name' => '唐雪见', 'age' => 15, 'sex' => '女', 'email' => 'txj@xj3.cn', 'password' => '123456' ), array( 'id' => 4, 'name' => '龙葵', 'age' => 15, 'sex' => '女', 'email' => 'lk@xj3.cn', 'password' => '123456' ), array( 'id' => 5, 'name' => '紫萱', 'age' => 100, 'sex' => '女', 'email' => 'zx@xj3.cn', 'password' => '123456' ) ); $title = '用户信息表'; $tabletitle = $title; $a = count($arr); function arrr($arr){ $data = ''; foreach ($arr as $ar){ $data.='<tr>'; $data.='<td>'.$ar['id'].'</td>'; $data.='<td>'.$ar['name'].'</td>'; $data.='<td>'.$ar['age'].'</td>'; $data.='<td>'.$ar['sex'].'</td>'; $data.='<td>'.$ar['email'].'</td>'; $data.='<td>'.$ar['password'].'</td>'; } return $data; } ?> <!DOCTYPE html> <html lang="en"> <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; } table > caption { font-size: 1.2rem; margin-bottom: 15px; } table + p { text-align: center; } </style> </head> <body> <table> <caption><?php echo $tabletitle ?></caption> <thead> <tr> <th>编号</th> <th>姓名</th> <th>年龄</th> <th>性别</th> <th>邮箱</th> <th>密码</th> </tr> </thead> <tbody> <?php echo arrr($arr) ?> </tbody> </table> <p>总计:<?php echo $a ?>人</p> </body> </html>
点击 "运行实例" 按钮查看在线实例