Home > Backend Development > PHP Tutorial > 求分析这个php函数的功能

求分析这个php函数的功能

WBOY
Release: 2016-06-06 20:19:56
Original
1324 people have browsed it

<code>  function assign($tpl_var, $value = null)
    {
        if (is_array($tpl_var)){
            foreach ($tpl_var as $key => $val) {
                if ($key != '') {
                    $this->_tpl_vars[$key] = $val;
                }
            }
        } else {
            if ($tpl_var != '')
                $this->_tpl_vars[$tpl_var] = $value;
        }
    }</code>
Copy after login
Copy after login

小菜刚开始学php。看了些关于函数和类的文章了,但是这个函数里面的_tpl_vars这个数组是怎么来的??
这个函数又实现了什么功能

回复内容:

<code>  function assign($tpl_var, $value = null)
    {
        if (is_array($tpl_var)){
            foreach ($tpl_var as $key => $val) {
                if ($key != '') {
                    $this->_tpl_vars[$key] = $val;
                }
            }
        } else {
            if ($tpl_var != '')
                $this->_tpl_vars[$tpl_var] = $value;
        }
    }</code>
Copy after login
Copy after login

小菜刚开始学php。看了些关于函数和类的文章了,但是这个函数里面的_tpl_vars这个数组是怎么来的??
这个函数又实现了什么功能

查看你的类属性~~~
然后你执行函数后,你在var_dump你的类属性~~~~~

$this 是自身类,你这个函数是类里面的一个函数, $this->_tpl_vars 是类里面的变量。
应该是少东西导致你看不懂了

Related labels:
php
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template