PHP list all variables


 

PHP list all variables

In this part of the tutorial we will learn how to list all variables in context of PHP list.And we will also see the example related to the get_defined_vars() function and ArrayObject class

In this part of the tutorial we will learn how to list all variables in context of PHP list.And we will also see the example related to the get_defined_vars() function and ArrayObject class

  • PHP all declared and environment variables can be listed
  • get_defined_vars() method returns all the variables in the form of array.
  • The array returned is handles by the class ArrayObject class.


Example of PHP List of all Variables

<?php
    $name
="roseindia";
    $city
="new delhi";
    $arr1
= new ArrayObject(get_defined_vars());

    foreach
($arr1 as $key=>$val)
    echo
"<br> key---->".$key." value------>".$val;
?>

Output
key---->GLOBALS value------>Array
key---->_ENV value------>Array
key---->HTTP_ENV_VARS value------>Array
key---->_POST value------>Array
key---->HTTP_POST_VARS value------>Array
key---->_GET value------>Array
key---->HTTP_GET_VARS value------>Array
key---->_COOKIE value------>Array
key---->HTTP_COOKIE_VARS value------>Array
key---->_SERVER value------>Array
key---->HTTP_SERVER_VARS value------>Array
key---->_FILES value------>Array
key---->HTTP_POST_FILES value------>Array
key---->_REQUEST value------>Array
key---->name value------>roseindia
key---->city value------>new delhi

Ads