PHP get_define_vars() 函数返回一个多维数组,其中包含所有已定义变量、环境变量、服务器变量或用户定义变量的列表变量,在调用该函数的范围内。
语法
get_defined_vars()
参数
不需要参数。
返回值
返回包含所有变量的多维数组。
示例:
下面的示例显示了 get_define_vars 的用法() 函数。
<?php
$x = array(1, 2, 3, 4, 5);
$result = get_defined_vars();
//显示结果数组
print_r($result);
?>
上述代码的输出将是:
Array
(
[_GET] => Array
(
)
[_POST] => Array
(
)
[_COOKIE] => Array
(
)
[_FILES] => Array
(
)
[argv] => Array
(
[0] => Main.php
)
[argc] => 1
[_SERVER] => Array
(
[APACHE_RUN_DIR] => /var/run/apache2
[APACHE_PID_FILE] => /var/run/apache2/apache2.pid
[JOURNAL_STREAM] => 8:22712
[PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
[INVOCATION_ID] => 135fb1968e1a4ae6a2fa49896ea1d5a4
[APACHE_LOCK_DIR] => /var/lock/apache2
[LANG] => C
[APACHE_RUN_USER] => www-data
[APACHE_RUN_GROUP] => www-data
[APACHE_LOG_DIR] => /var/log/apache2
[PWD] =>
[PHP_SELF] => Main.php
[SCRIPT_NAME] => Main.php
[SCRIPT_FILENAME] => Main.php
[PATH_TRANSLATED] => Main.php
[DOCUMENT_ROOT] =>
[REQUEST_TIME_FLOAT] => 1630049839.4612
[REQUEST_TIME] => 1630049839
[argv] => Array
(
[0] => Main.php
)
[argc] => 1
)
[x] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
)
)