PHP | get_defined_vars() Function

Last Updated : 27 Nov, 2018
Comments
Improve
Suggest changes
Like Article
Like
Report
The get_defined_vars() function is an inbuilt function in PHP which is used to returns an array of all defined variables. This function returns a multidimensional array which contains all the list of variables, environment etc. Syntax:
array get_defined_vars( void )
Parameters: This function does not accepts any parameter. Return Value: This function returns a multidimensional array of all the variables. Below program illustrates the get_defined_vars() function in PHP: Program: PHP
<?php

// Declare an array and initialize it
$a = array(0, 1, 2, 3, 4);

// Use get_defined_vars() function
$a = get_defined_vars();

// Display the output
print_r($a);
?>
Output:
Array
(
    [_GET] => Array
        (
        )

    [_POST] => Array
        (
        )

    [_COOKIE] => Array
        (
        )

    [_FILES] => Array
        (
        )

    [argv] => Array
        (
            [0] => /home/9485b6f3bafb5e0e7b2d4580a85e639d.php
        )

    [argc] => 1
    [_SERVER] => Array
        (
            [PHP_SELF] => /home/9485b6f3bafb5e0e7b2d4580a85e639d.php
            [SCRIPT_NAME] => /home/9485b6f3bafb5e0e7b2d4580a85e639d.php
            [SCRIPT_FILENAME] => /home/9485b6f3bafb5e0e7b2d4580a85e639d.php
            [PATH_TRANSLATED] => /home/9485b6f3bafb5e0e7b2d4580a85e639d.php
            [DOCUMENT_ROOT] => 
            [REQUEST_TIME_FLOAT] => 1543316494.2727
            [REQUEST_TIME] => 1543316494
            [argv] => Array
                (
                    [0] => /home/9485b6f3bafb5e0e7b2d4580a85e639d.php
                )

            [argc] => 1
        )

    [a] => Array
        (
            [0] => 0
            [1] => 1
            [2] => 2
            [3] => 3
            [4] => 4
        )

)
Reference: http://php.net/manual/en/function.get-defined-vars.php

Next Article

Similar Reads