Home > Backend Development > PHP Tutorial > PHP Operator (3) 'Assignment Operator' Example Explanation

PHP Operator (3) 'Assignment Operator' Example Explanation

怪我咯
Release: 2023-03-07 12:14:01
Original
2861 people have browsed it

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
?>
Copy after login

Run results:

PHP Operator (3) Assignment Operator Example Explanation

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!

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