批改状态:合格
老师批语:
<?php
// 员工信息
$staffs = [
['id'=>1, 'name'=>'候亮平', 'age'=>30, 'sex'=>1, 'hiredate'=> time(), 'mobile'=>'13899776655'],
['id'=>2, 'name'=>'赵瑞龙', 'age'=>40, 'sex'=>1, 'hiredate'=> time(), 'mobile'=>'13576543210'],
['id'=>3, 'name'=>'李达康', 'age'=>50, 'sex'=>1, 'hiredate'=> time(), 'mobile'=>'18955135522'],
['id'=>4, 'name'=>'祁同伟', 'age'=>45, 'sex'=>1, 'hiredate'=> time(), 'mobile'=>'13388888110'],
['id'=>5, 'name'=>'高小琴', 'age'=>30, 'sex'=>0, 'hiredate'=> time(), 'mobile'=>'15798986666'],
];
// 标题
$title = '员工信息表';
// 表格标题
$tableTitle = $title;
// 员工数量
$total = count($staffs);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>员工管理系统</title>
<style type="text/css">
*{margin: 0px;padding: 0px;}
ul{list-style: none;}
.nav{width: 100%;height: 80px;border-bottom:1px solid #333;}
.nav_box{width: 1000px;height: 80px;margin: 0 auto;line-height: 80px;}
.l{float: left;}
.nav a,p{float:right;}
.nav h2{float: left;}
.nav span{border-left: 1px solid #333; margin:0 10px;height: 40px;}
.box{width: 100%;height: 600px;}
.box-l{width: 400px;height: 600px;border-right: 1px solid #333;position: relative;float: left;}
ul{position: absolute;right: 50px;top: 50px;line-height: 60px;}
ul li a{text-decoration: none;}
ul li:hover a{color: #ff64b2;}
.box-r{float: left;position: relative;}
table{position: absolute;top: 50px;left: 100px;}
</style>
</head>
<body>
<div class="nav">
<div class="nav_box">
<h2>员工管理系统</h2>
<p>管理员:admin<span></span><a href="">退出</a></p>
</div>
</div>
<div class="box">
<div class="box-l">
<ul>
<li><a href="#">员工管理</a></li>
<li><a href="">系统设置</a></li>
<li><a href="">用户设置</a></li>
</ul>
</div>
<div class="box-r">
<table border="1" width="800">
<thead>
<tr style="background: #ADD8E6;">
<th>编号</th>
<th>姓名</th>
<th>年龄</th>
<th>性别</th>
<th>手机</th>
<th>入职</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<?php foreach($staffs as $staff) : ?>
<tr>
<td><?php echo $staff['id']; ?></td>
<td><?php echo $staff['name']; ?></td>
<td><?php echo $staff['age']; ?></td>
<td>
<?php if($staff['sex'] == 1) : ?>
男
<?php else: ?>
女
<?php endif; ?>
</td>
<td><?=$staff['mobile']?></td>
<td>
<?php
echo date('Y/m/d',$staff['hiredate']);
?>
</td>
<td>
<button onclick="location.href='#'">编辑</button>
<button onclick="location.href='#'"><span style="color:red">删除</span></button>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
</div>
</div>
</body>
</html>点击 "运行实例" 按钮查看在线实例
笔记:
函数:
isset() 判断一个变量是否存在
print_r()打印数组的值和类型
unset()销毁一个变量
array_may(callback,arr...)对数组中每个元素调用指定函数进行处理
自定义方法
return 结束php语句,并返回一个结果
格式:function 方法名(){函数语句}
自定义可以传参也可以不传参
调用方法:方法名();
匿名函数
函数的参数类型可以是一个函数,这个函数叫回调参数
匿名函数是一个临时函数,主要用作函数回调参数的值
三元运算符:
return $value % 2 != 0 ? $value : null;
如果值除以2后余数为0就返回值,否则返回空
快捷的if判断,叫三元运算符
条件 ? 成立 : 不成立
. 连接符
.= 连接后,并赋值给变量
如 $a=123;
$a.=456
最后输出$a=123456
函数,属于php系统创建的方法.
我们创建的函数,叫方法.方法创建后是不执行的,需要调用,才会执行.
return 只是返回数据
echo 是输出方法
自定义方法,都是用rutern返回的.因为我们创建方法不一定马上就要输出出来,所以
不用echo
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号