Home  >  Article  >  Backend Development  >  PHP assignment operation

PHP assignment operation

高洛峰
高洛峰Original
2016-10-29 10:11:571447browse

Assignment operation:=, which means that the value of the expression on the right is assigned to the operand on the left.

$int1=10;
$int1=$int1-6; //$int1=4

echo $int1,"<br>"; 

$int3=$int2=$int1+4;  //右向左,最后$int3=8

echo $int2,"<br>"; 
echo $int3,"<br>"; 



$int3=($int2=$int1)+4;  //先对()进行运算,再右向左,最后$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 "<hr>";
echo $int_x,"<br>"; 
echo $int_y,"<br>";

3. Reference assignment

$x=6;$y=$x;$z=&$y; //means $y, $z Two variables point to the same data

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn