PHP assignment, php assignment

Source: Internet
Author: User

PHP assignment, php assignment

 

1. Value assignment: =, indicating the number of operations assigned to the left by the value of the expression on the right.

$ Int1 = 10; $ int1 = $ int1-6; // $ int1 = 4 echo $ int1, "<br>"; $ int3 = $ int2 = $ int1 + 4; // right to left, last $ int3 = 8 echo $ int2, "<br>"; echo $ int3, "<br> "; $ int3 = ($ int2 = $ int1) + 4; // calculate () First, right to left, and finally $ int3 = 8 echo $ int2, "<br>"; echo $ int3, "<br> ";

 

2. Swap the values of two variables

$int_x=10;$int_y=20;$int_x=$int_y+$int_x;$int_y=$int_x-$int_y;$int_x=$int_x-$int_y;echo "

 

3. Value assignment

$ X = 6; $ y = $ x; $ z = & $ y; // It means that $ y and $ z point to the same data.

Graphical description. variables on the left and values on the right are the corresponding values. $ z = & $ y indicates $ y, and $ z indicates that the two variables point to a data 6. For example, the pointer in C, point to the same address.

echo var_dump($x,$y,$z),"<br>"; 

The output is: int (6) int (6) int (6)

 

Next, change the values of $ x and $ y to see the changes:

$x=4;$y=8;

echo var_dump($x,$y,$z),"<br>"; 

The output is: int (4) int (8) int (8)

Let's make the following changes at this time. Then let's look at the changes in $ x, $ y, and $ z:

$ X = $ y + 10; $ y = & $ x; // indicates that the value of $ y points to the value of $ x, $ z = $ y + 2;

echo var_dump($x,$y,$z),"<br>"; 

The output is: int (18) int (18) int (20)

Next, let's take another example to deepen our understanding:

// For a clear description, unset ($ x); unset ($ y); unset ($ z); unset ($ u ); $ x = 1; $ y = 2; $ z = 3; $ u = & $ z; echo "

View output results:

Int (1) int (2) int (3) int (3)
Int (1) int (1) int (1) int (3)
Int (5) int (5) int (5) int (3)
Int (5) int (5) int (5) int (5)
Int (6) int (6) int (6) int (6)

 

Finally, the complete test code is listed:

<? Php // 1. Value assignment: =, indicating the number of operations assigned to the left by the value of the right expression. $ Int1 = 10; $ int1 = $ int1-6; // $ int1 = 4 echo $ int1, "<br>"; $ int3 = $ int2 = $ int1 + 4; // right to left, last $ int3 = 8 echo $ int2, "<br>"; echo $ int3, "<br> "; $ int3 = ($ int2 = $ int1) + 4; // calculate () First, right to left, and finally $ int3 = 8 echo $ int2, "<br>"; echo $ int3, "<br>"; // 2. swaps the values of two variables $ int_x = 10; $ int_y = 20; $ int_x = $ int_y + $ int_x; $ int_y = $ int_x-$ int_y; $ int_x = $ int_x-$ int_y; echo " 

(End .)

 

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.