There are two operators that can be used to concatenate (join) strings.

PHP

Operator Description Example Equivalent to
. Concatenation $a = "Hi" . " there"  
.= Concatenation assignment $a .= "Hello" $a = $a . "Hello"

Java

Operator Description Example Equivalent to
+ Concatenation a = "Hi" + " there"  
+= Concatenation assignment a += "Hello" a = a + "Hello"

C++

Operator Description Example Equivalent to
+ Concatenation a = "Hi" + " there"  
+= Concatenation assignment a += "Hello" a = a + "Hello"

C#

Operator Description Example Equivalent to
+ Concatenation a = "Hi" + " there"  
+= Concatenation assignment a += "Hello" a = a + "Hello"

Visual Basic

Operator Description Example Equivalent to
& Concatenation a = "Hi" & " there"  
&= Concatenation assignment a &= "Hello" a = a & "Hello"

Python

Operator Description Example Equivalent to
+ Concatenation a = "Hi" + " there"  
+= Concatenation assignment a += "Hello" a = a + "Hello"

The following example displays “What’s up, dude?”

PHP

Java

C++

C#

Visual Basic

Python

Leave a Reply

Your email address will not be published. Required fields are marked *

This article is taken from a book of mine. If you enjoyed it, please visit my author's page inand check out all of my books!