如何检查是否在PHP中设置了环境变量?

In PHP, how do I test whether an environment variable is set? I would like behavior like this:

// Assuming MYVAR isn't defined yet.
isset(MYVAR); // returns false
putenv("MYVAR=foobar");
isset(MYVAR); // returns true

getenv() returns false if the environment variable is not set. The following code will work:

// Assuming MYVAR isn't defined yet.
getenv("MYVAR") !== false; // returns false
putenv("MYVAR=foobar");
getenv("MYVAR") !== false; // returns true

Be sure to use the strict comparison operator (!==) because getenv() normally returns a string that could be cast as a boolean.

This is what you need

    $var = getenv(MYVAR)
    if(isset($var)) {

    } else {

    }

you can check like this

if($ip = getenv('REMOTE_ADDR'))
echo $ip; 

getenv() Returns the value of the environment variable.