• PHP Video Tutorials

PHP - get_defined_vars() Function



Definition and Usage

The function get_defined_vars() returns array of all defined variables.

Syntax

array get_defined_vars ()

Parameters

None

Return Values

This function returns a multidimensional array containing a list of all defined variables.

Dependencies

PHP 4.0.4 and above.

Example

Following example demonstrates use of get_defined_vars() function −

<?php
   // Declare an array and initialize it
   $a = array(0, 1, 2, 3, 4);
   // Use get_defined_vars() function
   $arr = get_defined_vars();

   // print $arr
   print_r($arr);
?>

Output

This will produce following result −

Array (
[_GET] => Array ( )
[_POST] => Array ( )
[_COOKIE] => Array ( )
[_FILES] => Array ( )
[a] => Array (
   [0] => 0
   [1] => 1
   [2] => 2
   [3] => 3
   [4] => 4
))

As you can see this function returns a multidimensional array containing a list of all defined variables (environment, server or user-defined variables) within the scope that get_defined_vars() is called.

php_variable_handling_functions.htm
Advertisements