Home > Backend Development > PHP Tutorial > What are the assignment operators in php?

What are the assignment operators in php?

下次还敢
Release: 2024-04-27 11:21:26
Original
759 people have browsed it

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.

What are the assignment operators in php?

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

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

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

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

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

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

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!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template