-1

How do I declare a variable with part of another variable plus some text at the end like this but without the syntax error...

$filename = $foreachvar['base_var']'.jpg';
4

3 回答 3

7

You need the string concatenation operator:

$filename = $foreachvar['base_var'] . '.jpg';
                                    ^---

or, in a different way:

$filename = "{$foreachvar['base_var']}.jpg";
于 2012-09-19T15:22:15.593 回答
5

Using the concatenation operator:

$filename = $foreachvar['base_var'] . '.jpg';

You can also use the curly syntax:

$filename = "{$foreachvar['bae_var']}.jpg";
于 2012-09-19T15:21:52.367 回答
1
$filename = $foreachvar['base_var'] . '.jpg';

That's just assigning a value to the variable, which looks like what you're trying to do.

于 2012-09-19T15:22:01.990 回答