Easy Tutorial
❮ Php Sessions Func Filesystem Link ❯

PHP get_defined_vars() Function

Available PHP Functions

The getdefinedvars() function returns an array containing a list of all defined variables.

Version Requirements: PHP 4 >= 4.0.4, PHP 5, PHP 7

Syntax

array get_defined_vars ( void )

Parameter Description:

Return Value

Returns a multidimensional array containing a list of all defined variables, including environment variables, server variables, and user-defined variables.

Example

<?php
$b = array(1, 1, 2, 3, 5, 8);

$arr = get_defined_vars();

// Print $b
print_r($arr["b"]);

// Print the path of the PHP interpreter (if PHP is used as a CGI)
// For example: /usr/local/bin/php
echo $arr["_"];

// Print command line arguments (if any)
print_r($arr["argv"]);

// Print all server variables
print_r($arr["_SERVER"]);

// Print all available keys of the variables array
print_r(array_keys(get_defined_vars()));
?>

Execution result is as follows:

Array
(
    [0] => 1
    [1] => 1
    [2] => 2
    [3] => 3
    [4] => 5
    [5] => 8
)
Array
(
    [0] => /tmp/543750210/main.php
)
Array
(
    [PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    [HOSTNAME] => glot-runner
    [PHPIZE_DEPS] => autoconf        dpkg-dev        file        g++        gcc        libc-dev        make        pkg-config        re2c
    [PHP_INI_DIR] => /usr/local/etc/php
    [PHP_CFLAGS] => -fstack-protector-strong -fpic -fpie -O2
    [PHP_CPPFLAGS] => -fstack-protector-strong -fpic -fpie -O2
    [PHP_LDFLAGS] => -Wl,-O1 -Wl,--hash-style=both -pie
    [GPG_KEYS] => 1729F83938DA44E27BA0F4D3DBDB397470D12172 B1B44D8F021E4E2D6021E995DC9FF8D3EE5AF27F
    [PHP_VERSION] => 7.2.1
    [PHP_URL] => https://secure.php.net/get/php-7.2.1.tar.xz/from/this/mirror
    [PHP_ASC_URL] => https://secure.php.net/get/php-7.2.1.tar.xz.asc/from/this/mirror
    [PHP_SHA256] => 6c6cf82fda6660ed963821eb0525214bb3547e8e29f447b9c15b2d8e6efd8822
    [PHP_MD5] => 
    [HOME] => /home/glot
    [PHP_SELF] => /tmp/543750210/main.php
    [SCRIPT_NAME] => /tmp/543750210/main.php
    [SCRIPT_FILENAME] => /tmp/543750210/main.php
    [PATH_TRANSLATED] => /tmp/543750210/main.php
    [DOCUMENT_ROOT] => 
    [REQUEST_TIME_FLOAT] => 1524198667.12
    [REQUEST_TIME] => 1524198667
    [argv] => Array
        (
            [0] => /tmp/543750210/main.php
        )

    [argc] => 1
)
Array
(
    [0] => _GET
    [1] => _POST

[2] => _COOKIE [3] => _FILES [4] => argv [5] => argc [6] => _SERVER [7] => b [8] => arr ) ```

Available PHP Functions

❮ Php Sessions Func Filesystem Link ❯