Re: Dynamic Variable names
| From: | Adam Royle | Date: | Sun, 09 Mar 2003 13:06:57 +0000 |
| Subject: | Re: Dynamic Variable names | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-26201@lists.php.net to get a copy of this message | ||
It's probably better to use arrays.
$tips[0] = "value";
$tips[1] = "value";
$tips[2] = "value";
Although, if you REALLY want dynamic variable names.
$i = 1;
$varname = 'tips_'.$i;
$$varname = "value";
this will make a variable like below:
$tips_1 = "value";
But like I said before, it's better to use arrays - they are much more flexible (and PHP arrays are especially cool).
http://www.php.net/manual/en/ref.array.php
adam
Just a quick question about dynamic variables would like to end up with a variable called $tips_1 $tips_2 ... $tips_n where "n" is the value of the variable $sid i have tried $tips . '$sid'; and other variants, but i can't get one that doesn't return a parse error or T_VARIABLE error.