tags:

views:

212

answers:

3

I have three strings:

$str1 = "abc"; $str2 = "def"; $str3 = "ghi";

I can get the value of all of them like this:

echo "$str1$str2$str3";

But I heard there is a way to join them together, so I can echo all of them without quotes.

+6  A: 

You're looking for string concantation.

It's

echo $str1 . $str2 . $str3;

See http://nz2.php.net/language.operators.string for more information.

Norse
+2  A: 

How about:

echo $str1 . $str2 . $str3;
Ben
+5  A: 

As well as concatenating like this

echo $str1 . $str2 . $str3;

You can also just output them in sequence, which avoids evaluating an intermediate string

echo $str1 , $str2 , $str3;

Finally, you can use braces in string to disambiguate string replacement:

echo "{$str1}{$str2}{$str3}";
Paul Dixon