Home > Article > Backend Development > What are the assignment operators in php?
PHP assignment operators are used to assign values to variables, including: the single equal sign (=) assigns the right value to the left variable; plus equals (=) adds the right value to the left variable and assigns it; subtract Equal (-=) subtracts the left variable from the rvalue and assigns it; multiply equal (*=) multiplies the left variable by the right value and assigns it; divide equal (/=) divides the left variable by the right value and assigns it; modulo equals ( %=) takes the left variable modulo the rvalue and assigns it.
PHP Assignment Operator
Assignment operator in PHP is used to assign a value to a variable. They include:
1. Single equal sign (=)
The most commonly used assignment operator. It assigns the value on the right to the variable on the left.
Example:
<code class="php">$x = 10;</code>
2. Add Equals (=)
Adds the value on the right to the variable on the left and assigns the result.
Example:
<code class="php">$x += 5; // 等价于 $x = $x + 5</code>
3. Subtract Equals (-=)
Subtract the value on the right from the variable on the left and assign the result.
Example:
<code class="php">$x -= 2; // 等价于 $x = $x - 2</code>
4. Multiply equals (*=)
Multiply the variable on the left by the value on the right and assign the result.
Example:
<code class="php">$x *= 3; // 等价于 $x = $x * 3</code>
5. Division equals (/=)
Divides the variable on the left by the value on the right and assigns the result.
Example:
<code class="php">$x /= 2; // 等价于 $x = $x / 2</code>
6. Modulo equals (%=)
Take the variable on the left modulo the value on the right and assign the result.
Example:
<code class="php">$x %= 3; // 等价于 $x = $x % 3</code>
The above is the detailed content of What are the assignment operators in php?. For more information, please follow other related articles on the PHP Chinese website!