Page 1 of 1

variable problem

Posted: Fri Jan 10, 2003 11:07 am
by MedaXis
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

the concatenation operator is the period

Posted: Fri Jan 10, 2003 11:16 am
by lostboy
so to do what you want, do this

$i = 5;
$v="var_";
$v.$i //will gove the result of var_5

hth

Posted: Fri Jan 10, 2003 11:29 am
by Rob the R
To add to what lostboy said, to use the new name as a variable, you need to enclose it in curly braces:

Code: Select all

<?php
$i = 5 ;
${"var_" . $i} = "I am $var_5" ;
?>
The PHP manual on variable variables describes this.

Posted: Fri Jan 10, 2003 11:42 am
by MedaXis
thanks to both of you!

Steve