getenv
Description
The getenv of Options / Information for PHP gets the value of an environment variable.
Syntax
getenv( ?string $name = null, bool $local_only = false ): string|array|false
Parameters
name
The variable name as a string or null.
local_only
When set to true, only local environment variables are returned, set by the operating system or putenv. It only has an effect when name is a string.
Return
Returns the value of the environment variable name, or false if the environment variable name does not exist. If name is null, all environment variables are returned as an associative array.
Examples
1 · void
<? $return = getenv(); print_r($return);
Array ( [PATH] => /usr/local/bin:/bin:/usr/bin )
2 · name · null
<? $name = null; $return = getenv($name); print_r($return);
Array ( [PATH] => /usr/local/bin:/bin:/usr/bin )
3 · name · string
<? $name = "PATH"; $return = getenv($name); echo $return;
/usr/local/bin:/bin:/usr/bin
4 · local_only
<? $name = "PATH"; $local_only = true; $return = getenv($name, $local_only); echo $return;
/usr/local/bin:/bin:/usr/bin
5 · Superglobal
<? $name = "PATH"; $return = $_SERVER[$name]; echo $return;
/usr/local/bin:/bin:/usr/bin
Links
Options / Information
- assert
- assert_options
- cli_get_process_title
- cli_set_process_title
- dl
- extension_loaded
- gc_collect_cycles
- gc_disable
- gc_enable
- gc_enabled
- gc_mem_caches
- gc_status
- get_cfg_var
- get_current_user
- get_defined_constants
- get_extension_funcs
- get_include_path
- get_included_files
- get_loaded_extensions
- get_required_files
- get_resources
- getlastmod
- getmygid
- getmyinode
- getmypid
- getmyuid
- getopt
- getrusage
- ini_alter
- ini_get
- ini_get_all
- ini_parse_quantity
- ini_restore
- ini_set
- memory_get_peak_usage
- memory_get_usage
- memory_reset_peak_usage
- php_ini_loaded_file
- php_ini_scanned_files
- php_sapi_name
- php_uname
- phpcredits
- phpinfo
- phpversion
- putenv
- set_include_path
- set_time_limit
- sys_get_temp_dir
- version_compare
- zend_thread_id
- zend_version