棒棒忙这个函数到底是讲的什么意思啊解决思路

WBOY
Release: 2016-06-13 10:34:43
Original
994 people have browsed it

棒棒忙这个函数到底是讲的什么意思啊?
//读取与设置配置项 (这里的注释的意思就读取和设置。我是在想不通是什么设置和读取的啦谢谢大神!!!)

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->function C($name=null,$value=null){        static $config=array();//配置项        if(is_null($name)){            return $config;        }        if(!is_null($name)){            if(is_string($name)){                $name = strtolower($name);                if(is_null($value)){                    return isset($config[$name])?$config[$name]:false;                }                $config[$name]=$value;            }elseif(is_array($name)){                $name = array_change_key_case($name,CASE_LOWER);                $config = array_merge($config,$name);            }            }    }
Copy after login


------解决方案--------------------
妙处在于 static $config 的使用,当离开函数作用域事它的值并不会消失,而会保留最近一次的值。
这样看就清楚了:
PHP code
c("hello", "I say hello"); //一次赋值c(array("a", "b"));   //二次赋值var_dump( c());array(3) {  ["hello"]=>  string(11) "I say hello"  [0]=>  string(1) "a"  [1]=>  string(1) "b"}<div class="clear">
                 
              
              
        
            </div>
Copy after login
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!