Sunday, January 18, 2026
HomeLanguagesPHP | get_defined_vars() Function

PHP | get_defined_vars() Function

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
  
// 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

RELATED ARTICLES

Most Popular

Dominic
32474 POSTS0 COMMENTS
Milvus
118 POSTS0 COMMENTS
Nango Kala
6846 POSTS0 COMMENTS
Nicole Veronica
11977 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12063 POSTS0 COMMENTS
Shaida Kate Naidoo
6985 POSTS0 COMMENTS
Ted Musemwa
7219 POSTS0 COMMENTS
Thapelo Manthata
6933 POSTS0 COMMENTS
Umr Jansen
6911 POSTS0 COMMENTS