一、使用foreach/if替代语法循环遍历二维数组
实例
<?php $staffs = [ ['id'=>1, 'name'=>'候亮平', 'age'=>30, 'sex'=>1, 'email'=>'hlp@php.cn', 'password'=>sha1('123456')], ['id'=>2, 'name'=>'赵瑞龙', 'age'=>40, 'sex'=>1, 'email'=>'zrl@php.cn', 'password'=>sha1('123456')], ['id'=>3, 'name'=>'李达康', 'age'=>50, 'sex'=>1, 'email'=>'ldk@php.cn', 'password'=>sha1('123456')], ['id'=>4, 'name'=>'祁同伟', 'age'=>45, 'sex'=>1, 'email'=>'qtw@php.cn', 'password'=>sha1('123456')], ['id'=>5, 'name'=>'高小琴', 'age'=>30, 'sex'=>0, 'email'=>'gxq@php.cn', 'password'=>sha1('123456')], ]; ?> <?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 echo $staff['sex']?'男':'女';?></td> <!--if()替代语法--> <!-- <td>--><?php //if($staff['sex']===1) :?> <!-- 男--> <!-- --><?php //else:?> <!-- 女--> <!-- --><?php //endif;?> <!-- </td>--> <td><?php echo $staff['email'];?></td> <td><?php echo $staff['password'];?></td> </tr> <?php endforeach; ?>
运行实例 »
点击 "运行实例" 按钮查看在线实例
二、员工管理系统
使用<a>标签的target属性 与iframe 的name属性
实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>员工管理系统</title> <style> /*样式重置*/ *{margin:0;padding:0;} /*头部样式*/ .header{width: 100%;height: 60px;border-bottom: 1px solid #0f0f0f; line-height: 60px;} .h_content{width:1000px;margin: 0 auto;background-color:#e7e7e7;} .h_content span{ float: left; font-size: 18px; font-weight: bold;} .h_content p{ float: right;} .h_content p a{list-style: none;text-decoration: none;} /*中部样式*/ .main{width:1000px; min-height: 500px; margin: 0 auto; position: relative;} /*中左样式*/ .m_left{width:150px; /*继承最小高度*/ min-height:inherit; margin-top: 10px; position: absolute; top: 0; left: 0; background-color:lightblue;} .m_left ul li{list-style-type: none; margin: 10px;} .m_left ul li a{ text-decoration: none; color: #000000;} .m_left ul li a:hover{ color:red; } /*中右样式*/ .m_right{width:850px; /*继承最小高度*/ min-height:inherit; margin-top: 10px; position: absolute; top: 0; left: 150px;} .m_right iframe{ width: 850px; min-height: inherit; border: none; } </style> </head> <body> <!--头部--> <div class="header"> <div class="h_content"> <span>员工管理系统</span> <p>管理员: admin | <a href="">退出</a></p> </div> </div> <!-- 中部 --> <div class="main"> <!-- 中左部分 --> <div class="m_left"> <ul> <li><a href="staff_list.php" target="workspace">员工管理</a></li> <li><a href="system.php" target="workspace">系统设置</a></li> <li><a href="user_list.php" target="workspace">用户设置</a></li> </ul> </div> <!-- 中右部分 --> <div class="m_right"> <iframe src="staff_list.php" name="workspace"></iframe> </div> </div> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例