[SOLVED] Trouble With Variable Variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

[SOLVED] Trouble With Variable Variables

Post by Crashin »

I am trying to set some variable variables for use further down my script. I've got:

Code: Select all

<?php
// ...other code to get results from DB...
$i = 1;

while($array2 = mysql_fetch_assoc($result)) &#123;
	$me&#123;$i&#125; = $array2&#1111;'me'];
	$myself&#123;$i&#125; = $array2&#1111;'myself'];
	isset($array2&#1111;'andI']) ? $andI&#123;$i&#125; = $array2&#1111;'andI'] : $andI&#123;$i&#125; = NULL;
	$i++;
&#125;

echo $me1;
echo $myself1;
echo isset($andI1) ? $andI1 : "";
?>
But, when I try to access the variable variables they don't produce anything (i.e. nothing is output to the screen). :?:

I've found that if I make the variable variables static (e.g. $me1 instead of $me{$i}), I get what I'm expecting.
Last edited by Crashin on Fri Mar 04, 2005 12:16 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$&#123;'andI' . $i&#125;
I believe.
User avatar
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

Post by Crashin »

feyd, I am continually amazed at how fast you come up with solutions. Thanks you for your help. That was exactly the problem. :D
Post Reply