hi everyone
I'd like to create a variable like this:
$i = 5;
["var_" + $i] = "this is the value";
where ["var_" + $i] will be the variable name (in this example that would be var_5
how can I accomplish this?
Steve
variable problem
Moderator: General Moderators
the concatenation operator is the period
so to do what you want, do this
$i = 5;
$v="var_";
$v.$i //will gove the result of var_5
hth
$i = 5;
$v="var_";
$v.$i //will gove the result of var_5
hth
To add to what lostboy said, to use the new name as a variable, you need to enclose it in curly braces:
The PHP manual on variable variables describes this.
Code: Select all
<?php
$i = 5 ;
${"var_" . $i} = "I am $var_5" ;
?>