Home > Backend Development > PHP Tutorial > What is the symbol that connects two strings in php?

What is the symbol that connects two strings in php?

下次还敢
Release: 2024-04-27 15:21:18
Original
1031 people have browsed it

The operator that connects two strings in PHP is the dot operator (.), and its syntax is $str1 . $str2. The dot operator joins two string values ​​together, returning a new string. Notes include: only applies to string values, has lower priority, and can be used to concatenate arrays.

What is the symbol that connects two strings in php?

Operator to connect two strings in PHP

In PHP, you can connect two strings Use the dot operator (.).

Syntax:

<code class="php">$str1 . $str2;</code>
Copy after login

Where:

  • $str1 and $str2 are The string to be concatenated.
  • The dot operator (.) concatenates two strings together.

Example:

<code class="php">$str1 = "Hello";
$str2 = "world";
$result = $str1 . $str2; //结果为 "Hello world"</code>
Copy after login

The dot operator concatenates $str1 and $str2 into new characters string$result.

Note:

  • The dot operator can only connect string type values.
  • Concatenating null values ​​produces no output.
  • The dot operator has lower precedence than arithmetic operators and string comparison operators. Therefore, parentheses can be used to force precedence when needed.
  • The dot operator can also be used to connect arrays.

The above is the detailed content of What is the symbol that connects two strings in php?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template