What is php assignment operator?
The most basic form of the assignment operator is "=". The "=" here does not mean "equal", but means assignment. Its function is simply to assign a value to a variable. For example, $A=10 means assigning 10 to $A, so the value of $A is 10.
Extended knowledge about php operators: 1."php arithmetic operators detailed explanation" 2."php string operator examples explained"
Of course this Just the most basic assignment operator. In addition to the most basic "=" assignment operator, we also have other forms of assignment operators, which we call compound assignment operators, as shown in the following table
Operator | Explanation | Example | is equivalent to | Meaning |
= | Assignment | $a=b | $a=b | Assign the value on the right to the left |
+= | Add | $a+=b | $a=$a+b | Add the value on the right to the left |
-= | minus | $a-=b | $a=$a-b | Subtract the value on the right to the left |
*= | Multiply | $a*=b | $a=$a*b | Multiply the value on the right by the value on the left divided by |
/= | $a/=b | $a=$a/b | Divide the value on the right by the value on the left | |
.= | Connection characters | $a.=b | #$a=$a.b | Add the characters on the right to the left |
% | Get the remainder | $a%=b | $a=$a+%b | Take the remainder of the value on the left to the right |
php assignment operator example
The code is as follows
<?php $a=20; echo $a."<br/>"; // 输出 20 $y=20; $y += 80; echo $y."<br/>"; // 输出 100 $z=50; $z -= 25; echo $z."<br/>"; // 输出 25 $i=5; $i *= 5; echo $i."<br/>"; // 输出 25 $j=10; $j /= 5; echo $j."<br/>"; // 输出 2 $k=15; $k %= 4; echo $k."<br/>"; // 输出 3 ?>
Run results:
The above example is a basic application of the assignment operator. I hope you can further develop and apply it based on the basics. In the next chapter we will explain the "bit operator" in PHP operators.
The above is the detailed content of PHP Operator (3) 'Assignment Operator' Example Explanation. For more information, please follow other related articles on the PHP Chinese website!