PHP operator (2) "string operator" example

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

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.