What is a string operator? The function of the string operator is to connect two strings to form a new string.
What is a string operator?
String operator introduction: a string operator is used to concatenate two strings to form a new string.
We have introduced the arithmetic operators in PHP operators in the previous sections. I believe you have some knowledge about the "arithmetic operators" in PHP operators. today, we will introduce in detail the"String operators".
In PHP, we provide two string operators::
First: connection operators"." Indicates that it connects two strings to form a new string.
Type 2: value assignment join operator, Use ". = "indicates the combination of" string operator "and" value assignment operator "in the PHP operator. for the value assignment concatenation operator, we will explain it in detail in the following sections.
Therefore, we can also say that there is only one string operator, that is, the first "string concatenation operator", represented.
PS: In PHP, "+" is only used as an arithmetic operator and cannot be used as a string operator. in the following example, we will compare the differences between the two.
String operator instance
This example is used for comparison.The difference between "." and "+"When ". ", the variables $ a and $ B form a new string 1.5a * 11, but if" + "is used, PHP considers it an operation. At this time, if there is a string type on both sides of the "+", PHP will automatically convert to an integer type. if there is a letter, it will be output as 0. if it is a string starting with a number, the number in the string header is truncated for computation.
The instance code is as follows:
"; $ Ba = $ a + $ B; // use the". + "operator to connect two variables to echo $ ba;?>
The output result is as follows:
The above example shows that ". the difference between "and" + "can also be seen in the initial application of the string operator. in the next section, we will detail the value assignment operator in PHP operations.
The above is a detailed description of the PHP operator (2) "string operator" instance. For more information, see other related articles in the first PHP community!