Home >Backend Development >PHP Tutorial >The concatenation of strings in php is
The string concatenation character in PHP is the period (.), which concatenates strings to generate new strings and automatically converts non-strings into strings. The period operator is also used in string concatenation, interpolation, and object calling.
PHP string concatenation character
The string concatenation character in PHP is period (.) . It is used to concatenate two or more strings to produce a new string. For example:
<code class="php">$str1 = "Hello"; $str2 = "World"; $newStr = $str1 . " " . $str2; // "Hello World"</code>
When you use periods to concatenate strings, PHP will automatically convert them to the string type. Therefore, the following code will also produce the same output:
<code class="php">$num1 = 10; $num2 = 20; $result = $num1 . $num2; // "1020"</code>
Additional usage:
In addition to concatenating strings, the period operator can also be used for the following purposes:
<code class="php">$name = "John"; $age = 30; $address = "123 Main Street"; $info = "Name: $name, Age: $age, Address: $address";</code>
<code class="php">$greeting = "Hello, $name!"; // "Hello, John!"</code>
<code class="php">$obj->property; // 访问对象的属性 $obj->method(); // 调用对象的メソッド</code>
The above is the detailed content of The concatenation of strings in php is. For more information, please follow other related articles on the PHP Chinese website!