<?php $arr = [ ['id' => 1 , 'name'=>'123','age' => '35','sex'=>'1'], ['id' => 2 , 'name'=>'456','age' => '34','sex'=>'0'], ['id' => 3 , 'name'=>'789','age' => '43','sex'=>'1'], ['id' => 4 , 'name'=>'110','age' => '56','sex'=>'0'], ]; //数组总数量 $Total = count($arr); //标题 $tit = '用户表' //浏览器title // $ttit = $tit; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title><?php $ttit ?></title> </head> <body> <table> <thead> <tr> <th>ID</th> <th>名字</th> <th>年龄</th> <th>性别</th> </tr> </thead> <tbody> $tab = ''; <?php foreach ($arr as $k) { $tab .= '<tr>'; $tab .='<td>'.$k{'id'}.'</td>'; $tab .='<td>'.$k{'name'}.'</td>'; $tab .='<td>'.$k{'age'}.'</td>'; $tab .='<td>'.($k{'sex'} ? '男' : '女').'</td>'; $tab .='</tr>'; } echo $tab; ?> </tbody>总数是 <?php echo $Total; ?> </table> </body> </html>
点击 "运行实例" 按钮查看在线实例