PHP operator (ii) example of "string operator"

Source: Internet
Author: User
Tags arithmetic operators php operator
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.