CKTIS / PHP
Bitwise XOR with assignment (^=)
Toggle the flags selected by the mask in the variable.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
$value ^= $operandToggle the flags selected by the mask in the variable. Applying the same mask twice restores the previous settings.
A mask works on individual bits of integers. When both operands are strings, PHP operates on their bytes and returns a string. A result bit is 1 when exactly one corresponding input bit is 1.
Evaluation
$value = 12; $value ^= 10;→6$value = 12; $value ^= 0;→12$value = 7; $value ^= 7;→0
Examples
<?php
$value = 12;
$value ^= 10;
echo json_encode($value), PHP_EOL;
$value = 12;
$value ^= 0;
echo json_encode($value), PHP_EOL;
$value = 7;
$value ^= 7;
echo json_encode($value), PHP_EOL;
Result
6 12 0