Assignment operators in PHP

Assignment operators in PHP

In PHP, assignment operators are used to assign values to variables. There are several assignment operators available in PHP, including the basic assignment operator (=) and combined operators such as +=, -=, *=, /=, %=, .=, <<=, >>=, &=, ^=, and |=.

The basic assignment operator (=) is used to assign a value to a variable, while the combined operators perform arithmetic or bitwise operations before assigning the result to the variable.

For example, the operator += adds the value on the right-hand side of the operator to the value on the left-hand side and assigns the result to the left-hand side variable. So, $a += $b is the same as $a = $a + $b.

Similarly, the operator .= concatenates the string on the right-hand side of the operator with the string on the left-hand side and assigns the result to the left-hand side variable. So, $a .= $b is the same as $a = $a . $b. Assignment operators are a useful tool for writing concise and efficient code in PHP.

Apply for PHP Certification!

https://www.vskills.in/certification/certified-php-developer

Back to Tutorials

Get industry recognized certification – Contact us

Menu