Posted by John Holmes on 01/18/05 06:28
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
Navigation:
[Reply to this message]
|