<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style type="text/css"> table{border: 1px solid #ccc;text-align: center;margin: 0 auto;} td{height: 30px;width: 150px} h1{text-align: center} </style> </head> <body> <?php $a = '员工信息表'; echo '<h1>'.$a.'</h1>';?> //表头 <table> <tr> <td>编号</td> <td>姓名</td> <td>性别</td> <td>年龄</td> <td>地址</td> </tr> <?php $array_1 = array( array(1,'阿朱1','男',20,'玉溪市'), array(2,'阿朱2','男',20,'玉溪市'), array(3,'阿朱3','男',20,'玉溪市'), array(4,'阿朱4','男',20,'玉溪市'), array(5,'阿朱5','男',20,'玉溪市'), array(6,'阿朱6','男',20,'玉溪市'), array(7,'阿朱7','男',20,'玉溪市'), ); $length1 = count($array_1);//获取二维数组的一级数组数量 $length = $length1 * 5;//数组总长(7*5=35) $c = 0;//二维数组中 一级数组的索引序号 for ($length;$length > 0;$length--){ if ($length % 5 == 0){ //通过求余数来判断是否是一个tr内的循环 echo '<tr>'; for ($b = 0;$b < 5;$b++){ echo '<td>'.$array_1[$c][$b]; } $c = $c + 1; //$array—_1数组 下一个下标自动加1 } } ?> </table> </body> </html>