PHP 超全局变量

示例

超全局变量由PHP定义,并且始终可以在没有global关键字的任何地方使用。

<?php

function getPostValue($key, $default = NULL) {
    // $_POST是一个超全局变量,可以不使用
    // 必须指定“全局$_POST;”
    if (isset($_POST[$key])) {
        return $_POST[$key];
    }

    return $default;
}

// 检索$_POST ['username']
echo getPostValue('username');

// 检索$_POST ['email'],默认为空字符串
echo getPostValue('email', '');