<?php
header("Content-type:text/html;charset=utf-8");
$lasy= [
['id'=>1,'name'=>'成龙','gj'=>'中国','xb'=>'男','dbz'=>'《醉拳》《警察的故事》'],
['id'=>2,'name'=>'甄子丹','gj'=>'中国','xb'=>'男','dbz'=>'《叶问》《一个人的武林》'],
['id'=>3,'name'=>'赵文卓','gj'=>'中国','xb'=>'男','dbz'=>'《风云》《锻刀》'],
['id'=>4,'name'=>'张晋','gj'=>'中国','xb'=>'男','dbz'=>'《叶问》《杀破狼》'],
['id'=>5,'name'=>'邹兆龙','gj'=>'中国','xb'=>'男','dbz'=>'《冒险王》《不二神探》'],
];
$len=count($lasy);
$title='武林英雄帖';
$bgtitle='名单';
function lasyse($lasy){
$vs='';
foreach($lasy as $las){
$vs.='<tr>';
$vs.='<td>'.$las['id'].'</td>';
$vs.='<td>'.$las['name'].'</td>';
$vs.='<td>'.$las['gj'].'</td>';
$vs.='<td>'.$las['xb'].'</td>';
$vs.='<td>'.$las['dbz'].'</td>';
}
return $vs;
}
?>
<!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: 50px auto;
}
</style>
</head>
<body>
<table>
<caption>
<?php echo '<span style="color: #9ACD32;">'.$bgtitle.'</span>'; ?>
</caption>
<tr>
<th>id</th>
<th>姓名</th>
<th>国籍</th>
<th>性别</th>
<th>代表作</th>
</tr>
<tbody>
<?php echo lasyse($lasy); ?>
</tbody>
</table>
<p style="text-align: center;">人数:<?php echo $len; ?>人</p>
</body>
</html>点击 "运行实例" 按钮查看在线实例
<?php
header("Content-type:text/html;charset=utf-8");
$lasy = [
['id'=>1, 'name'=>'候亮平', 'age'=>30, 'sex'=>'男', 'email'=>'hlp@qq.com', 'password'=>sha1('123456')],
['id'=>2, 'name'=>'赵瑞龙', 'age'=>40, 'sex'=>'男', 'email'=>'zrl@qq.com', 'password'=>sha1('123456')],
['id'=>3, 'name'=>'李达康', 'age'=>50, 'sex'=>'男', 'email'=>'ldk@qq.com', 'password'=>sha1('123456')],
['id'=>4, 'name'=>'祁同伟', 'age'=>45, 'sex'=>'男', 'email'=>'qtw@qq.com', 'password'=>sha1('123456')],
['id'=>5, 'name'=>'高小琴', 'age'=>30, 'sex'=>'女', 'email'=>'gxq@qq.com', 'password'=>sha1('123456')],
];
$rens=count($lasy);
$title='用户信息表';
//表格标题
$bgtitle = $title;
//创建函数:动态生成员工表格
//函数参数:表格数据(数组)
function lasys($lasy){
//1、创建空变量保存数据 2、数组也是接收的值 3、循环数组
$boxlasy = '';
foreach($lasy as $las){
$boxlasy.='<tr>';
$boxlasy.='<td>' . $las['id'] . '</td>';
$boxlasy.='<td>'.$las['name'].'</td>';
$boxlasy.='<td>'.$las['age'].'</td>';
$boxlasy.='<td>'.($las['sex'] ? '男' : '女').'</td>';
$boxlasy.='<td>'.$las['email'].'</td>';
$boxlasy.='<td>'.$las['password'].'</td>';
$boxlasy.='</tr>';
}
echo $boxlasy;
}
?>
<!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;
}
tbody tr:hover {
background-color: #efefef;
}
table > caption {
font-size: 1.2rem;
margin-bottom: 15px;
}
table + p {
text-align: center;
}
</style>
</head>
<body>
<table>
<caption>
<?php echo '<span style="color: #9ACD32;">'.$bgtitle.'</span>'; ?></caption>
<thead>
<tr>
<th>编号</th>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
<th>邮箱</th>
<th>密码</th>
</tr>
</thead>
<tbody>
<?php echo lasys($lasy); ?>
</tbody>
</table>
<p>总计: <?php echo $rens ?>人</p>
</body>
</html>点击 "运行实例" 按钮查看在线实例
<?php
header("Content-type:text/html;charset=utf-8");
$lasy = [
['id'=>1, 'name'=>'候亮平', 'age'=>30, 'sex'=>'男', 'email'=>'hlp@qq.com', 'password'=>sha1('123456')],
['id'=>2, 'name'=>'赵瑞龙', 'age'=>40, 'sex'=>'男', 'email'=>'zrl@qq.com', 'password'=>sha1('123456')],
['id'=>3, 'name'=>'李达康', 'age'=>50, 'sex'=>'男', 'email'=>'ldk@qq.com', 'password'=>sha1('123456')],
['id'=>4, 'name'=>'祁同伟', 'age'=>45, 'sex'=>'男', 'email'=>'qtw@qq.com', 'password'=>sha1('123456')],
['id'=>5, 'name'=>'高小琴', 'age'=>30, 'sex'=>'女', 'email'=>'gxq@qq.com', 'password'=>sha1('123456')],
];
$rens=count($lasy);
$title='用户信息表';
//表格标题
$bgtitle = $title;
//创建函数:动态生成员工表格
//函数参数:表格数据(数组)
function lasys($lasy){
//1、创建空变量保存数据 2、数组也是接收的值 3、循环数组
$boxlasy = '';
foreach($lasy as $las){
$boxlasy.='<tr>';
$boxlasy.='<td>' . $las['id'] . '</td>';
$boxlasy.='<td>'.$las['name'].'</td>';
$boxlasy.='<td>'.$las['age'].'</td>';
$boxlasy.='<td>'.($las['sex'] ? '男' : '女').'</td>';
$boxlasy.='<td>'.$las['email'].'</td>';
$boxlasy.='<td>'.$las['password'].'</td>';
$boxlasy.='</tr>';
}
echo $boxlasy;
}
?>
<!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-bottom: 15px;
}
table + p {
text-align: center;
}
</style>
</head>
<body>
<table>
<caption>
<?php echo '<span style="color: #9ACD32;">'.$bgtitle.'</span>'; ?></caption>
<thead>
<tr>
<th>编号</th>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
<th>邮箱</th>
<th>密码</th>
</tr>
</thead>
<tbody>
<?php echo lasys($lasy); ?>
</tbody>
</table>
<p>总计: <?php echo $rens ?>人</p>
</body>
</html>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号