Jump to content

2 variables stuck together


briant

Recommended Posts

Do you want to create a variable which is called what $test holds and add $num to the name. For example:

$test - holds myvar
$num - holds the number 1

You can to create a variabled valled myvar1

You'll do this:
[code=php:0]${'myvar' . $num} = 'blah blah';

// echo the variable that was created above.
echo $myvar1;[/code]
I forgot the test var. This is what my example should be:
[code=php:0]$test = 'myvar';
$num = 1;

${$test. $num} = 'blah blah';

// echo the variable that was created above.
echo $myvar1;[/code]

However its stull the same. Just that I had myvar 'hardcoded' in.
However, instead of constructing varables with names like "$myvar1", "$myvar2" and having
[code]
$myvar1 = 'blah';
$myvar2 = 'blah blah';
[/code]
it's a lot easier and more convenient to store in an array
[code]
$myvar = array();
$myvar[1] = 'blah';
$myvar[2] = 'blah blah';
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.