if the title seems too vague.. uhm i wanted to display every variable that i used to generate a page along with their variable names and values, is it possible and how?
foreach($_SESSION as $varname => $value) {
print "<b>".$varname."</b> = $value <br/>";
}
^the above sample is what i use to display all session variables, what if i need to display the variables i set to display the page? are they registered also in some form of an array or should i also echo them individually?
You can use get_defined_vars()
which will give you an array of all variables declared in the scope that the function is called including globals like $_SESSION
and $_GET
. I would suggest printing it like so:
echo '<pre>' . print_r(get_defined_vars(), true) . '</pre>';
The easiest way to do this is with get_defined_vars().
From the Documentation
This function returns a multidimensional array containing a list of all defined variables, be them environment, server or user-defined variables, within the scope that get_defined_vars() is called.
Producing a var_dump of this array will provide you with an extensive list.
var_dump( get_defined_vars() );
A couple other interesting functions in the same area are get_defined_constants() and get_included_files()...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With