分配算子将分配算子右值或是式的结果到左的变量中。
运算符 | 符号 | 使用 例 | 备注 |
---|---|---|---|
assignment | = | $var = 1 | assign 1 to $var |
addition | += | $var += 1 | assign result of $var + 1 to $var |
subtraction | -= | $var -= 1 | assign result of $var - 1 to $var |
multiplication | *= | $var *= 2 | assign result of $var * 2 to $var |
division | /= | $var /= 2 | assign result of $var / 2 to $var |
the rest | %= | $var %= 2 | assign result of $var % 2 to $var |
concatenate | .= | $var .= "string" | assign result of $var . "string" to $var |
bitwise AND | &= | $var &= 0x02 | assign result of $var & 0x02 to $var |
bitwise OR | |= | $var |= 0x02 | assign result of $var | 0x02 to $var |
bitwise XOR | ^= | $var ^= 0x02 | assign result of $var ^ 0x02 to $var |
left shift | <<= | $var <<= 4 | assign result of $var << 4 to $var |
right shift | >>= | $var >>= 4 | assign result of $var >> 4 to $var |