Home>Article>Backend Development> PHP Operator (2) Detailed explanation of "String Operator" examples

PHP Operator (2) Detailed explanation of "String Operator" examples

怪我咯
怪我咯 Original
2017-04-12 15:15:40 3453browse

What are string operators?

Introduction to string operators: The function of string operators is to concatenate two strings to form a new string.

We introduced thearithmetic operatorsamong PHP operators in the previous chapter. I believe you already have some understanding of the "arithmetic operators" among PHP operators. Today, we will give you a detailed introduction to the "String operator" in PHP operators.

In PHP, there are two types of string operatorsprovided for us:

The first one: connection operator, use " ." means that its function is to connect two strings to form a new string.

Second type: assignment connection operator, represented by ".=", which is the combination of "string operator" and "assignment operator" in PHP operators Combination, regarding the assignment connection operator, we will give you a detailed explanation in the following chapters.

So it can also be said that there is only one string operator, which is the first "string concatenation operator", represented by ".".

PS: There is something to note here. In PHP, the "+" sign is only used as an arithmetic operator and cannot be used as a string operator. In the following example, we will compare Explain the difference between the two.

String operator examples

This example is used to compare the difference between"." and "+" signs, when When "." is used, the two strings of variables $a and $b form a new string 1.5a*11, but if the "+" sign is used, PHP will consider this to be an operation. At this time, if there are string types on both sides of the "+" sign, PHP will automatically convert it to an integer type. If there are letters, it will be output as 0. If it is a string starting with a number, the characters will be intercepted. The number at the head of the string is being calculated.

The example code is as follows:

"; $ba=$a+$b; ////使用".+"运算符将两个变量进行连接 echo $ba; ?>

The output result is as follows:

PHP Operator (2) Detailed explanation of String Operator examples

It will be fine through the above example You can see the difference between "." and "+", and you can also see the preliminary application of string operators. In the next section, we will introduce in detail the assignment operatorinPHP operations.



The above is the detailed content of PHP Operator (2) Detailed explanation of "String Operator" examples. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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