Home > Backend Development > PHP Tutorial > php模板原理讲解_PHP

php模板原理讲解_PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 11:57:38
Original
1160 people have browsed it
复制代码 代码如下:
$data = array(
        'title'=>'ilsea',
        'list'=>array(
                'hello',
                'world'
            )
    );

include('show.php');

// show.php 模板文件

        echo $data['title'];
    echo '
';
    print_r($data['list']);
    ?>


定义一个函数用来包含模板,并传递数据
复制代码 代码如下:
// 定义一个函数用来包含模板,并传递数据,应该定义在公用函数库里的,这里我就直接写在这儿了
function template($template,$data)
{
    if(isset($data)){
        foreach($data as $key=>$val){
            $$key = $val;
        }
        unset($data);
    }
    include($template);
}

template('show.php',$data);

此例当然不是完整的写法,仅仅是一个小小的示例,模板赋值的原理就是这样的。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template