Home > Backend Development > PHP Tutorial > PHP assignment operation

PHP assignment operation

高洛峰
Release: 2016-10-29 10:11:57
Original
1463 people have browsed it

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>";
Copy after login

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>";
Copy after login

3. Reference assignment

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

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template