Re: variable
| From: | Ben Dunlap | Date: | Thu, 24 Sep 2009 17:23:22 +0000 |
| Subject: | Re: variable | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-298329@lists.php.net to get a copy of this message | ||
> Suppose I have a variable $i = 0 or 1 or 2
> and I have variables $item0, $item1 and $item2
> how do I print the variable $item0 using a combination of variable $item and
> variable $i?
> or with this code it gives me an error:
> $i = 0;
> $item0 = "test";
> echo $item$i; #how do I properly use this variable $item with $i?
$var = "item$i";
echo $$var;
Note the two dollar-signs in the second line.
I wonder if a basic array would make for easier-to-read code, though:
$items = array( "test" );
$i = 0;
echo $items[$i];
Ben