what is a string operator?
Introduction to String Operators: The function of the string operator is to concatenate two strings to form a new string.
We introduced the arithmetic operators in the PHP operators in the previous chapters, and I believe that we have already learned about the "arithmetic operators" in the PHP operators, and today we give you a detailed description of the " string Operators " in the PHP operators.
in PHP, there are two types of string operators available to US :
The first type: The join operator , with "." Indicates that his role is to concatenate two strings together to form a new string.
The second type is the assignment join operator , denoted by ". =", which is the combination of the "string operator" and "assignment operator" in the PHP operator, and we will give you a detailed explanation of the assignment join operator in the following section.
So it can be said that there is only one string operator, that is, the first "string join Operator", with "." Said.
PS: There is a need to note that in PHP, the "+" is used only as an arithmetic operator, not as a string operator, in the following example, we will compare the difference between the two.
String operator instances
This example is used to compare "." and the "+" sign between the two , when using "." , the variable $ A and $b two strings form a new string 1.5a*11, but if you use the "+" sign, PHP will consider this an operation. At this point, if the "+" number on both sides of the string type, PHP will automatically convert to an integer type, where if there is a letter, will be as 0 output, if the string starts with a number, it will intercept the string head number, in the calculation.
The instance code is as follows:
< $a = "1.5a*1"; Declares a string variable, beginning with a number $b=1; What an integer variable $ab= $a. $b; Use the "." The operator connects two variables to the echo $ab. " <br/> "; $ba = $a + $b; Connect two variables using the ". +" operator Echo $ba;? >
The output results are as follows:
By the example above, we can see very well that "." and the "+" difference, you can see the initial application of the string operator, the next section, we will detail the assignment operator in PHP operations.