Expressions: Assignment Operations
Assignment Operator
Assignment can be used to assign a value to a variable using the =
operator, followed by the expression to assign to the left.
$foo = $bar;
Addition Assignment Operator
Addition assignment can be used to add a value to a variable using the +=
operator, followed by the expression to add to the left.
$foo += $bar;
Subtraction Assignment Operator
Subtraction assignment can be used to subtract a value from a variable using the -=
operator, followed by the expression to subtract from the left.
$foo -= $bar;
Multiplication Assignment Operator
Multiplication assignment can be used to multiply a value to a variable using the *=
operator, followed by the expression to multiply to the left.
$foo *= $bar;
Division Assignment Operator
Division assignment can be used to divide a value from a variable using the /=
operator, followed by the expression to divide from the left.
$foo /= $bar;
Modulus Assignment Operator
Modulus assignment can be used to get the modulus of a value from a variable using the %=
operator, followed by the expression to get the modulus from the left.
$foo %= $bar;
Exponentiation Assignment Operator
Exponentiation assignment can be used to exponentiate a value to a variable using the **=
operator, followed by the expression to exponentiate to the left.
$foo **= $bar;
Concatenation Assignment Operator
Concatenation assignment can be used to concatenate a value to a variable using the .=
operator, followed by the expression to concatenate to the left.
$foo .= $bar;
Bitwise And Assignment Operator
Bitwise and assignment can be used to bitwise and a value to a variable using the &=
operator, followed by the expression to bitwise and to the left.
$foo &= $bar;
Bitwise Or Assignment Operator
Bitwise or assignment can be used to bitwise or a value to a variable using the |=
operator, followed by the expression to bitwise or to the left.
$foo |= $bar;
Bitwise Xor Assignment Operator
Bitwise xor assignment can be used to bitwise xor a value to a variable using the ^=
operator, followed by the expression to bitwise xor to the left.
$foo ^= $bar;
Bitwise Shift Left Assignment Operator
Bitwise shift left assignment can be used to bitwise shift left a value to a variable using the <<=
operator, followed by the expression to bitwise shift left to the left.
$foo <<= $bar;
Bitwise Shift Right Assignment Operator
Bitwise shift right assignment can be used to bitwise shift right a value to a variable using the >>=
operator, followed by the expression to bitwise shift right to the left.
$foo >>= $bar;
Null Coalescing Assignment Operator
Null coalescing assignment can be used to assign a value to a variable if it is null using the ??=
operator, followed by the expression to assign to the left.
$foo ??= $bar;