您的位置:首页 > 编程语言

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

2008-07-21 10:49 225 查看
 
解读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函数,说明了其代码的严谨性
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息