批改状态:未批改
老师批语:
<?php
$array = [
['id'=>1,'name'=>'张三','age'=>20,'sex'=>1],
['id'=>2,'name'=>'李四','age'=>20,'sex'=>1],
['id'=>3,'name'=>'赵五','age'=>20,'sex'=>1],
['id'=>4,'name'=>'小梅','age'=>20,'sex'=>0],
['id'=>5,'name'=>'小兰','age'=>20,'sex'=>0],
];
$total = count($array);
$title = '用户信息表';
$tableTitle = $title;
function mainTable($array) {
$kong = '';
foreach ($array as $v) {
$kong .= '<tr>';
$kong .= '<td>' . $v['id'] . '</td>';
$kong .= '<td>' . $v['name'] . '</td>';
$kong .= '<td>' . $v['age'] . '</td>';
$kong .= '<td>' . ($v['sex'] ? '男' : '女') . '</td>';
$kong .= '</tr>';
}
return $kong;
}
?>
<!DOCTYLE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;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 '<span style="color:red">' . $tableTitle . '</span>';
?>
</caption>
<thead>
<tr>
<th>编号</th>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
</tr>
</thead>
<tbody>
<?php echo mainTable($array); ?>
</tbody>
</table>
<p>总计:
<?php echo $total; ?>
人</p>
</body>
</html>点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号