博主信息
博文 6
粉丝 0
评论 0
访问量 4655
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
0221作业
CY的博客
原创
749人浏览过

一、使用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>

运行实例 »

点击 "运行实例" 按钮查看在线实例

YY截图20190222152155.png

批改状态:不合格

老师批语:作业名称不合规则
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学