Page 1 of 1

Adding an underscore to the end of a variable does not work

Posted: Sat Mar 05, 2011 2:40 pm
by flycast
Code:

Code: Select all

$destUser = "theUser";
$destDBUser = "theDBUser";
echo "$destUser_$destDBUser";
Outputs:
theDBUser
not
theUser_theDBUser
Adding the underscore after the variable inside quotes supresses the variable in some way. Why?

Re: Adding an underscore to the end of a variable does not w

Posted: Sat Mar 05, 2011 4:12 pm
by Weirdan
because underscore is a valid character in a variable name and it's interpreted as $destUser_'s value followed by $destDBUser's value.

use curly braces, like this:

Code: Select all

echo "{$destUser}_{$destDBUser}"