Php assignment operator

Source: Internet
Author: User
The basic assignment operator is "". At first, we may think it is "equal", but it is not. It actually means assigning the value of the right expression to the number of operations on the left. The value of the value assignment expression is the value assigned. That is to say, the value of "$ a3" is 3. In this way, you can do some tips: the basic assignment operator is "= ". At first, we may think it is "equal", but it is not. It actually means assigning the value of the right expression to the number of operations on the left.

The value of the value assignment expression is the value assigned. That is to say, the value of "$ a = 3" is 3. In this way, you can do some tips:

 

For an array, the "=>" operator is used to assign values to keys with names. This operator has the same priority as other value assignment operators.

In addition to the basic value assignment operators, there are also "combined operators" suitable for all binary arithmetic, array sets, and string operators ", in this way, you can use its value in an expression and assign the result of the expression to it. for example:

 

Note that the value assignment operation copies the value of the original variable to the new variable (pass the value assignment), so changing one does not affect the other. This is also suitable for copying some values such as large arrays in dense loops.

In PHP, an exception to the normal value assignment behavior is that when an object is encountered, it is referenced and assigned in PHP 5 unless the clone keyword is explicitly used for copying.

Reference assignment

PHP supports reference assignment, using the "$ var = & $ othervar;" syntax. Referencing a value assignment means that two variables point to the same data without copying anything.

Example #1 reference assignment

 

Since PHP 5, the new operator automatically returns a reference. Therefore, an E_DEPRECATED error message is sent when the new result is referenced and assigned to PHP 5.3 and later versions, in earlier versions, an E_STRICT error message is sent.

For example, the following code generates a warning:

 

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.