RE: [PHP] How to show variables

From: Date: Fri, 13 Oct 2000 18:28:12 +0000
Subject: RE: [PHP] How to show variables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-20050@lists.php.net to get a copy of this message
At 3:30 PM +1000 10/13/00, Samantha Savvakis wrote:
create a page and put in it: <? phpinfo(); ?> -----Original Message----- From: Wayne Michel [mailto:wayne@michel.com.au] Sent: Friday, 13 October 2000 15:25 To: php-general@lists.php.net Subject: [PHP] How to show variables I am trying to write some code to teach myself PHP, etc. Is there a way to display all the variables currently set? regards, Wayne
And, if you want to show all internally set program vars, you can step through the $GLOBALS array: reset($GLOBALS); while (list($var, $value)=each($GLOBALS)) { echo "$var = $value<BR>\n"; } note that if one of these $var's is an array it will simply display 'Array'. With a little extra programming, you can fix that. A simple program that expands arrays by one level follows (using recursion, you could create a function that displayed arrays to any depth but - as they say - I'll leave that "as an exercize for the reader" ;) : reset($GLOBALS); while (list($var, $value)=each($GLOBALS)) { if (is_array($var)) { reset($var); while(list($var2, $value2)=each($var)) { echo "$var[$var2] = $value2<BR>\n"; } } else { echo "$var = $value<BR>\n"; } Just for hoots, you can also use variable variables; for instance, you could replace the line echo "$var = $value<BR>\n"; with echo "$var = ", $$var, "<BR>\n"; The usual untested/off-the-top-of-my-head/haven't-had-sufficient-caffiene caveats apply. -steve +--- "They've got a cherry pie there, that'll kill ya" ------------------+
| Steve Edberg                           University of California, Davis |
| sbedberg@ucdavis.edu                               Computer Consultant |
| http://aesric.ucdavis.edu/                  http://pgfsun.ucdavis.edu/ |
+-------------------------------------- FBI Special Agent Dale Cooper ---+

« previous php.general (#20050) next »