Is there a way in php to reset the names of all "all" with their corresponding value?

if the title seems too vague. I wanted to show every variable that I used to create the page along with the names and values โ€‹โ€‹of the variables, is it possible and how?

foreach($_SESSION as $varname => $value) { print "<b>".$varname."</b> = $value <br/>"; } 

^ the above example is what I use to display all session variables, what if I need to display the variables that I set to display the page? Are they registered in any form of array or should I also track them separately?

+7
debugging php
source share
3 answers

You can use get_defined_vars() , which will give you an array of all the variables declared in the area called by the function, including global variables like $_SESSION and $_GET . I would suggest printing it like this:

 echo '<pre>' . print_r(get_defined_vars(), true) . '</pre>'; 
+31
source share

The easiest way to do this is get_defined_vars () .

From the documentation

This function returns a multidimensional array containing a list of all defined variables, be it the environment, server, or user variables, within the scope called by get_defined_vars ().

Creating var_dump for this array will give you an extensive list.

 var_dump( get_defined_vars() ); 
+10
source share

A couple of other interesting functions in one area: get_defined_constants () and get_included_files () ...

+2
source share

All Articles