get_defined_vars

Returns an array of all defined variables

Syntax

get_defined_vars ( void ) : array

Return

A multidimensional array with all the variables.

Examples

1

<?

$return = get_defined_vars();

print_r($return);

?>
Array
(
    [_GET] => Array
        (
        )

    [_POST] => Array
        (
        )

    [_COOKIE] => Array
        (
        )

    [_FILES] => Array
        (
        )

    [_SERVER] => Array
        (
            [PATH] => /usr/local/bin:/bin:/usr/bin
            [HTTP_ACCEPT] => */*
            [HTTP_HOST] => osbo.com
            [HTTP_X_HTTPS] => 1
            [DOCUMENT_ROOT] => /home/osbocom/public_html
            [REMOTE_ADDR] => 212.1.210.51
            [REMOTE_PORT] => 22070
            [SERVER_ADDR] => 212.1.210.80
            [SERVER_NAME] => osbo.com
            [SERVER_ADMIN] => webmaster@osbo.com
            [SERVER_PORT] => 443
            [REQUEST_SCHEME] => https
            [REQUEST_URI] => /php/demo/
            [HTTPS] => on
            [X_SPDY] => HTTP2
            [SSL_PROTOCOL] => TLSv1.3
            [SSL_CIPHER] => TLS_AES_256_GCM_SHA384
            [SSL_CIPHER_USEKEYSIZE] => 256
            [SSL_CIPHER_ALGKEYSIZE] => 256
            [SCRIPT_FILENAME] => /home/osbocom/public_html/php/demo/index.php
            [QUERY_STRING] => 
            [SCRIPT_URI] => https://osbo.com/php/demo/
            [SCRIPT_URL] => /php/demo/
            [SCRIPT_NAME] => /php/demo/index.php
            [SERVER_PROTOCOL] => HTTP/1.1
            [SERVER_SOFTWARE] => LiteSpeed
            [REQUEST_METHOD] => GET
            [X-LSCACHE] => on
            [PHP_SELF] => /php/demo/index.php
            [REQUEST_TIME_FLOAT] => 1634568800.9581
            [REQUEST_TIME] => 1634568800
        )

)

2

<?

$variable1 = 0;
$variable2 = 12.34;
$variable3 = "abc";
$variable4 = array(1, 2, 3);

$return = get_defined_vars();

print_r($return);

?>
Array
(
    [_GET] => Array
        (
        )

    [_POST] => Array
        (
        )

    [_COOKIE] => Array
        (
        )

    [_FILES] => Array
        (
        )

    [_SERVER] => Array
        (
            [PATH] => /usr/local/bin:/bin:/usr/bin
            [HTTP_ACCEPT] => */*
            [HTTP_HOST] => osbo.com
            [HTTP_X_HTTPS] => 1
            [DOCUMENT_ROOT] => /home/osbocom/public_html
            [REMOTE_ADDR] => 212.1.210.51
            [REMOTE_PORT] => 22072
            [SERVER_ADDR] => 212.1.210.80
            [SERVER_NAME] => osbo.com
            [SERVER_ADMIN] => webmaster@osbo.com
            [SERVER_PORT] => 443
            [REQUEST_SCHEME] => https
            [REQUEST_URI] => /php/demo/
            [HTTPS] => on
            [X_SPDY] => HTTP2
            [SSL_PROTOCOL] => TLSv1.3
            [SSL_CIPHER] => TLS_AES_256_GCM_SHA384
            [SSL_CIPHER_USEKEYSIZE] => 256
            [SSL_CIPHER_ALGKEYSIZE] => 256
            [SCRIPT_FILENAME] => /home/osbocom/public_html/php/demo/index.php
            [QUERY_STRING] => 
            [SCRIPT_URI] => https://osbo.com/php/demo/
            [SCRIPT_URL] => /php/demo/
            [SCRIPT_NAME] => /php/demo/index.php
            [SERVER_PROTOCOL] => HTTP/1.1
            [SERVER_SOFTWARE] => LiteSpeed
            [REQUEST_METHOD] => GET
            [X-LSCACHE] => on
            [PHP_SELF] => /php/demo/index.php
            [REQUEST_TIME_FLOAT] => 1634568800.9714
            [REQUEST_TIME] => 1634568800
        )

    [variable1] => 0
    [variable2] => 12.34
    [variable3] => abc
    [variable4] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )

)

PHP

Home Menu