一段精妙的代码,反应了无尽的智慧

来源:互联网 发布:ubuntu 中文支持 编辑:程序博客网 时间:2024/04/25 10:23

 
解读zf     getPost

别看这个小小的函数,却提供了很多可变的功能

    /**
     * Retrieve a member of the $_POST superglobal
     *
     * If no $key is passed, returns the entire $_POST array.
     *
     * @todo How to retrieve from nested arrays
     * @param string $key
     * @param mixed $default Default value to use if key not found
     * @return mixed Returns null if key does not exist
     */
    public function getPost($key = null, $default = null)
    {
        if (null === $key) {
            return $_POST;
        }

        return (isset($_POST[$key])) ? $_POST[$key] : $default;
    }
 

 

1.获取全局的$_POST

2.返回相应key的POST

3.设置相应key的默认POST

4.注意isset函数,说明了其代码的严谨性

原创粉丝点击