Re: Echoing Variables Names

From: Date: Tue, 18 Jan 2005 04:28:18 +0000
Subject: Re: Echoing Variables Names
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-206617@lists.php.net to get a copy of this message
Phillip S. Baker wrote:
I am generating some variable variables. I am interested for testing purposes in finding out the names of the variables that are actually being generated. Since I want to make sure that that my following conditional statements are working properly and the values are set. So is there a way to print out the name of the variables?
I agree with the recommendation to just use an array. Variable variables are almost always just a workaround for an array. That being said, if you're creating the variable then you can create the name. If you're saying $a = 'x'; $b = 'y'; $c = 'z'; $xyz = 'foobar'; //Get name of "variable" $name = $a.$b.$c; // $name = "xyz" //Get value of variable $value = ${$a.$b.$c}; // $value = "foobar" Show some code if that doesn't clue you in. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.general (#206617) next »