博主信息
博文 34
粉丝 0
评论 0
访问量 46185
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
php基础——五期线上培训——2019-3-19
黄健的博客
原创
912人浏览过

今天的课程学到了函数:

    函数:有参数和无参数函数。

        无参数:function test(){ return 'sss' }

        有参数函数:

            必须传参;默认值传参

                必须:function  test ( $arr ) { return $arr; } 不传入参数报错。

                默认值: function  test ( $arr='空' ){ return $arr; } 

            函数可以多个参数  ;function test( $1, $2 ,$3... ){}


作业:循环拼装表格

    

实例

<?php
/**
 * Created by PhpStorm.
 * User: hello word!
 * Date: 2019/3/19
 * Time: 22:15
 */

header('content-type:text/html;charset=utf-8');
//漫画信息
$animate = [

    ['id'=>1, 'name'=>'火影', 'country'=>'jp','hot'=>0],
    ['id'=>2, 'name'=>'海贼', 'country'=>'jp','hot'=>1],
    ['id'=>3, 'name'=>'我的英雄学院', 'country'=>'jp','hot'=>0],
    ['id'=>4, 'name'=>'死神', 'country'=>'jp','hot'=>1],
    ['id'=>5, 'name'=>'全职猎人', 'country'=>'jp','hot'=>0],
];

$title='我喜欢的漫画';
$tableTitle="漫画列表";

function createTable($animate)
{
    $result = '';
    foreach ($animate as $v)
    {
        $result .= '<tr>';
        $result .= '<td>' . $v['id'] . '</td>';
        $result .= '<td>' . $v['name'] . '</td>';
        $result .= '<td>' . $v['country'] . '</td>';
        $result .= '<td>' . ($v['hot'] ? '热门' : '不热门') . '</td>';
        $result .= '</tr>';
    }
    return $result;
}
?>

<!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;
    }
    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 createTable($animate); ?>
    </tbody>
</table>
</body>
</html>

运行实例 »

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

总结:php与html的混编可以完成很多的东西。

批改状态:未批改

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系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+教程免费学