Page 1 of 1

[SOLVED] Trouble With Variable Variables

Posted: Fri Mar 04, 2005 12:09 pm
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.

Posted: Fri Mar 04, 2005 12:13 pm
by feyd

Code: Select all

$&#123;'andI' . $i&#125;
I believe.

Posted: Fri Mar 04, 2005 12:18 pm
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