Sunday, December 21, 2025
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
32455 POSTS0 COMMENTS
Milvus
111 POSTS0 COMMENTS
Nango Kala
6823 POSTS0 COMMENTS
Nicole Veronica
11958 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12038 POSTS0 COMMENTS
Shaida Kate Naidoo
6958 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6911 POSTS0 COMMENTS
Umr Jansen
6890 POSTS0 COMMENTS